Sunday, December 11, 2011

In VB.Net - How do I offer the ability for user to change the font of any individual control?

I can place the Font Dialog on the form. But in runtime the whole form is changed when this is called. How do I allow the user to choose which button, textbox, etc they want to change?In VB.Net - How do I offer the ability for user to change the font of any individual control?
You can click the button and have the font change on that. Or you can compare the control that you want with that one the page and change the font that way. Example;

If CType(lblTime, Label).Text = ';One'; Then

...

End If



But you will have to put that through a loop...



EXAMPLE:THIS IS TO LOOP THROUGH BUTTONS



Private Sub btnListAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListAll.Click

On Error Resume Next

'Looping through all the buttons using this code



'For Each GetButton as Control in Me.Controls

'If TypeOf GetButton Is Button then

'txtGetTest.Text %26amp;= GetButton.text %26amp; vbCrLf

'End If

'Next



'The problem is the code will NOT see the

'controls in the GroupBox's



'Reset the counter

m_ControlCount = 0

'Clear the textbox

txtGetText.Clear()

'Goto the user create sub

'Get the objects in Me( form )

ShowAll(Me)



'If code said ';ShowAll(Me.GroupBox1)';

'The oaContainer would return all the

'controls in the Groupbox ONLY



End Sub

Sub ShowAll(ByVal oaContainer As Control)

On Error Resume Next

'Get all the controls in the control area specified (Me)

For Each cntrl As Control In oaContainer.Controls

'If the current control in a button and

'the control is not blank then

If TypeOf cntrl Is Button AndAlso _

Not (cntrl.Text = Nothing) Then

'Add one(1) to the counter

m_ControlCount += 1

'Add counter and the

'control name to the nextbox

'START a new line

txtGetText.Text %26amp;= _

m_ControlCount %26amp; ';) '; %26amp; cntrl.Text %26amp; vbCrLf



End If

'Input this to show ALL the controls

'on the form

ShowAll(cntrl)

'Refresh the control

'IF Refresh() is NOT implemented

'Error will occur when user presses another button

cntrl.Refresh()

Next



End Sub

No comments:

Post a Comment