Visual Basi 6

2
First, add or remove the check sign. mnuViewStatus.Checked = Not mnuViewStatus.Checked ' Then make the status bar visible or not. staStatusBar.Visible = mnuViewStatus.Checked Accessing Menus at Run Time in Visual Basic 6 Menu controls expose only one event, Click. As you expect, this event fires when the user clicks on the menu: Private Sub mnuFileExit_Click() Unload Me End Sub You can manipulate menu items at run time through their Checked, Visible, and Enabled properties. For example, you can easily implement a menu item that acts as a switch and displays or hides a status bar: Private Sub mnuViewStatus_Click() ' First, add or remove the check sign. mnuViewStatus.Checked = Not mnuViewStatus.Checked ' Then make the status bar visible or not. staStatusBar.Visible = mnuViewStatus.Checked End Sub While menu items can be responsible for their own Checked status, you usually set their Visible and Enabled properties in another region of the code. You make a menu item invisible or disabled when you want to make the corresponding command unavailable to the user. You can choose from two different strategies to achieve this goal: You can set the menu properties as soon as something

Transcript of Visual Basi 6

Page 1: Visual Basi 6

First, add or remove the check sign.mnuViewStatus.Checked = Not mnuViewStatus.Checked' Then make the status bar visible or not.staStatusBar.Visible = mnuViewStatus.Checked

Accessing Menus at Run Time in Visual Basic 6

Menu controls expose only one event, Click. As you expect, this event fires when the user clicks on the menu:

Private Sub mnuFileExit_Click()Unload MeEnd Sub

You can manipulate menu items at run time through their Checked, Visible, and Enabled properties. For example, you can easily implement a menu item that acts as a switch and displays or hides a status bar:

Private Sub mnuViewStatus_Click()' First, add or remove the check sign.mnuViewStatus.Checked = Not mnuViewStatus.Checked' Then make the status bar visible or not.staStatusBar.Visible = mnuViewStatus.CheckedEnd Sub

While menu items can be responsible for their own Checked status, you usually set their Visible and Enabled properties in another region of the code. You make a menu item invisible or disabled when you want to make the corresponding command unavailable to the user. You can choose from two different strategies to achieve this goal: You can set the menu properties as soon as something happens that affects that menu command, or you can set them one instant before the menu is dropped down. Let me explain these strategies with two examples.

Let's say that the Save command from the File menu should look disabled if your application has loaded a read-only file. In this case, the most obvious place in code to set the menu Enabled property to False is in the procedure that loads the file, as shown in the code below.

Page 2: Visual Basi 6