Controlling color by option buttons and check boxes

 

Today I came across another VB question under the Yahoo! Answer section. It goes like this "Create a new project that lists the colors below in a option box. When a user chooses an option, the background to the form should change to this color.
Color Number
Blue 1
Green 2
Cyan 3
Red 4
Magenta 5
Yellow 6
White 7

The form should also have check boxes of Bold, Italic and Underline. When the user chooses a check box, the title of the relevant box should change to have the property indicated." . Below is the sample program for the above question:

 

Private Sub Check1_Click()
Check1.FontBold = True
End Sub

Private Sub Check2_Click()
Check2.FontItalic = True
End Sub

Private Sub Check3_Click()
Check3.FontUnderline = True
End Sub

Private Sub OptBlue_Click()
Form1.BackColor = vbBlue
End Sub

Private Sub OptGreen_Click()
Form1.BackColor = vbGreen
End Sub

Private Sub OptMag_Click()
Form1.BackColor = vbMagenta
End Sub

Private Sub OptRed_Click()
Form1.BackColor = vbRed
End Sub

Private Sub OptWhite_Click()
Form1.BackColor = vbWhite
End Sub

Private Sub OptYellow_Click()
Form1.BackColor = vbYellow
End Sub

 

Explanations

 To change the font properties  of a VB object or control, just set the particular property to true or false.

For example,      Check1.FontBold=True will set the caption of the check box to bold

To set the background to blue color, use the BackColor property and the color value vbBlue and etc.  

Form1.BackColor = vbBlue

 

 

 

 

 

 

 

 [Back to VBToday]