Graphics  and Common Dialog Box

Enter your search terms Submit search form




The program in this example allows the user to change the shape by selecting a particular shape from a list of options from a list box, as well as changing its color through a common dialog box.

 The objects to be inserted in the form are a list box, a command button, a shape control and a common dialog box. The common dialog box can be inserted by clicking on `project¨ on the menu and then select the Microsoft Common Dialog Control 6.0 by clicking the check box. After that, the Microsoft Common Dialog Control 6.0 will appear in the toolbox; and you can drag it into the form.

 The list of items can be added to the list box through the AddItem method. The procedure for the common dialog box to present the standard colors is as follows:

CommonDialog1.Flags = &H1&


Shape1.BackColor = CommonDialog1.Color

The last line will change the background color of the shape by clicking on a particular color on the common dialog box as shown in Figure

Private Sub Form_Load()

List1.AddItem "Rectangle"

List1.AddItem "Square"

List1.AddItem "Oval"

List1.AddItem "Circle"

List1.AddItem "Rounded Rectangle"

List1.AddItem "Rounded Square"

End Sub

 Private Sub List1_Click()

Select Case List1.ListIndex

Case 0

Shape1.Shape = 0

Case 1

Shape1.Shape = 1

Case 2

Shape1.Shape = 2

Case 3

Shape1.Shape = 3

Case 4

Shape1.Shape = 4

Case 5

Shape1.Shape = 5

End Select

End Sub


 Private Sub Command1_Click()

CommonDialog1.Flags = &H1&


Shape1.BackColor = CommonDialog1.Color

End Sub







 [Back to VBToday]