This document provides instructions for designing a menu in VB 6 to control shape properties. It involves 4 steps:
1. Create a form with a rectangle shape and color menu to select fill colors like red, blue, green.
2. Add a shape menu with submenus for oval, rectangle, square shapes and code to set the shape properties.
3. Create an apply color menu with submenus like transparent, solid fill and code to set the fill style.
4. Test the menus by selecting a color, shape and fill style to change the rectangle shape's properties. The menus allow dynamically changing the color, shape and fill of the rectangle.
2. VB 6 Design A Menu
Step 1: Create a New VB 6 form
Open visual basic 6 and choose Standard EXE and your default VB
form will show up. The
next step is to create a rectangle shape from the toolbar on the left
hand side of form. Here are the properties of the form.
Form Name: Menu_Form Caption: Menu Design BackColor :
Highlight Text
Width: 10515 Height: 6660
Create a rectangle shape with following properties. Do not change
other properties of shape.
Name : Shape1 Caption: Shape1 Border Width: 5
3. Form Design
Menu Design With Rectangular Shape
Step 2: Create Menu For Color
In this section, we will create a new menu to select a color for the shape.
Go to Tools > Menu Editor or right-click on the form and select Menu Editor.
Color Menu
In the Menu Editor, you must enter the values for Caption, Name. You can add
Shortcut if necessary. Select Next to add a new menu item and Delete to
remove an item from the menu.
To add a sub menu, select the right arrow ( ->) or to move the sub menu, up and
down arrow. Then you must add Caption, Name, and Shortcut for sub menu
items.
5. Color Menu With Sub Menu Items
Click each of the sub menu item and add following codes.
Private Sub blue_Click()
Shape1.FillColor = RGB(0, 0, 255)
End Sub
Private Sub green_Click()
Shape1.FillColor = RGB(0, 255, 0)
End Sub
Private Sub red_Click()
Shape1.FillColor = RGB(255, 0, 0)
End Sub
6. Step 3: Create Menu For Shapes
Now that you have created color menu, we must create Shape menu with three
sub menu for Oval, Rectangle, and Square shape.
To create this menu, follow all steps mentioned in step 2. Your Shape menu should
look like the following.
Shape Menu
Now the shape menu with three sub menu look like the following.
Shape Menu with three sub menu items
Add following codes by clicking each of the sub menu items of shape menu.
7. Private Sub MMenu_Click()
form1.Show
Form2.Visible = False
form1.Visible = True
End Sub
Private Sub Oval_Click()
Shape2.Shape = 3
Shape2.FillColor = RGB(218, 165, 32)
End Sub
Private Sub Rectangle_Click()
Shape2.Shape = 0
Shape2.FillColor = RGB(255, 215, 0)
End Sub
8. Private Sub Square_Click()
Shape2.Shape = 1
Shape2.FillColor = RGB(207, 181, 59)
End Sub
Step 4: Create Menu to Apply Colors
In this section, we create our last menu item that apply the color selected from the color
menu. Suppose you choose Green from color menu. It will not change the background
color of the shape unless you choose the fill style from apply color menu.
Follow step 2 to create a new menu called Apply Color. The menu should have the
following sub menu items.
Apply Color Menu
The final menu for the form will look like the following. Look at the sub menu for Apply
Color.
9. Sub Menu Items For Apply Color
Add the following codes for each sub menu by clicking on them.
Private Sub Transparent_Click()
Shape2.FillStyle = 1
End Sub
Private Sub Diag_Click()
Shape2.FillStyle = 7
End Sub
Private Sub Solid_Click()
Shape2.FillStyle = 0
End Sub
10. Testing the Project
Once you have saved your project. It is time to test it.
Color Menu = Choose the color for the shape. e.g Red,
Blue, Green Shape Menu = Choose the shape e.g
Oval, Rectangle, or Square
Apply Color = Apply the chosen color style. e.g
Transparent, or Solid Fill.
11. Select A Color
Select Oval Shape From Shape Menu Apply Solid Fill of Color
Green
The final step will apply solid fill of selected color green to the
shape. Note that you can change the color, shape, or fill at any
point in the program.