Page 216 - Open Soource Technologies 304.indd
P. 216

Event Driven Programming



                          9.5.2 Displaying a Check Mark on a Menu Control
                          Using the Checked property, we can place a check mark on a menu to:
                            • Tell the user the status of an on/off condition. Choosing the menu command alternately
                               adds and removes the check mark.
                            • Indicate which of several modes is in effect. The Options menu of the MDI Notepad
                               application uses a check mark to indicate the state of the toolbar, as shown in Figure 9.7.








                                                    Figure 9.7: A Checked  Menu  Item.

                          We create check marks in Visual Basic with the Checked property. Set the initial value of the
                          Checked property in the Menu Editor by selecting the check box labeled Checked. To add or
                          remove a check mark from a menu control at run time, set its Checked property from code. For
                          example:
                          Private Sub mnuOptions_Click ()
                             ‘ Set the state of the check mark based on
                             ‘ the Visible property.
                             mnuOptionsToolbar.Checked = picToolbar.Visible
                          End Sub
                          9.5.3 Making Menu Controls Invisible

                          In the Menu Editor, you set the initial value of the Visible property for a menu control by
                          selecting the check box labeled Visible. To make a menu control visible or invisible at run time,
                          set its Visible property from code. For example:
                          mnuFileArray(0).Visible = True   ‘ Make the control
                                                           ‘ visible.

                          mnuFileArray(0).Visible = False   ‘ Make the control
                                                           ‘ invisible.
                          When a menu control is invisible, the rest of the controls in the menu move up to fill the empty
                          space. If the control is on the menu bar, the rest of the controls on the menu bar move left to
                          fill the space.


                                        Making a menu control invisible effectively disables it, because the control
                                        is inaccessible from the menu, access or shortcut keys. If the menu title is
                                        invisible, all the controls on that menu are unavailable.







                          210                    LOVELY PROFESSIONAL UNIVERSITY
   211   212   213   214   215   216   217   218   219   220   221