Graphical User Interface (GUI)


 Controls 

Intrinsic Controls and ActiveX Controls 

 

   

 

 

Some Frequently Used Standard Controls  

ComboBox 

 

CheckBox  

If chkPreserve.Value = vbChecked Then  
    …  
Else  
    …  
EndIf

 

OptionButton  

Timer  

 

Creating a Menu System  

   

 

Private Sub MnuFile_Click( )

 

Steps for Defining a Menu Command  

  1. Select a menu command in the list. The last item in the list is always blank, so you can select it to add a new menu command.
  2. Type a Caption for the menu command.  As with other controls, use an ampersand (&) to specify an access key.  (Note: If the Caption property is set to a hyphen, VB inserts a separator bar between the items.)
  3. Type a Name property. Menu names should be prefixed with "mnu".  
  4. If needed, assign a shortcut key by selecting one from the Shortcut drop­down combo box. Shortcut keys must be unique for all menu commands on the form.  
     
  5. Set the Checked, Enabled, and/or Visible properties as necessary.
  6. Specify the menu command's order in the menu hierarchy by using the arrow buttons.  
  7. Repeat steps 1 through 6 for each menu command required.
  8. Click the OK button to close the Menu Editor dialog.

 

 

   

Pop-up Menu  

 

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)  
        ' When right button is clicked display Pop Up menu  
        If Button = vbRightButton Then  
               Call PopupMenu(mnuPopUp)  
        End If
End Sub  

 

Private Sub mnuSub_Click( )
        ' Performs action associated with sub menu item
        lblOutput.Caption = "Sub"
End Sub

 

Message Box  

The figure below includes an example of a message box.  Note the different features that can be customized by the programmer.

--------------------------

The TypeOfBox is determined by combining different groups of built-in integer constants.

TypeOfBox = ButtonType + IconType + ModalType + DefaultButton

 

The button type allows the programmer to specify the number and type of buttons that appear on the message box.   

 

The icon type allows the programmer to choose between four different types of icons to display in the message box.   

 

The modal type determines whether the user can can interact with other windows while the message box is displayed.  For application modal, the user cannot interact with other windows in the same application, but can still interact with other programs.  For system modal, the message box must be dismissed before any other action can take place in any application.

 

 

The default button is not shown in our text, but it allows the programmer to specify which button on the message box is the default.  

 

      

When the MsgBox function is used, it returns a value.  The table below lists the return values.     

 

Here is an example of the MsgBox statement: 

typeOfBox = vbOKOnly + vbInformation + vbApplicationModal
MsgBox "Enrollment recorded.", typeOfBox, "Status"

 

Here is an example of a MsgBox function call:

typeOfBox = vbOKCancel + vbExclamation + vbApplicationModal
response = MsgBox("OK to exit, Cancel to continue.", typeOfBox, "Exit")
If (response = vbOK) Then End        ' OK button pressed