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

Event Driven Programming



                          9.4.1 The Flags Argument
                          We use the flags argument in the PopupMenu method to further define the location and behavior
                          of a pop-up menu. The following table lists the flags available to describe a pop-up menu’s
                          location.
                                      Table 9.1:  Flags Available to Describe a Pop-up Menu’s Location

                               Location constants          Description

                               vbPopupMenuLeftAlign        Default. The specified x location defines the left edge
                                                           of the pop-up menu.
                               vbPopupMenuCenterAlign      The pop-up menu is centered around the specified x
                                                           location.
                               vbPopupMenuRightAlign       The specified x location defines the right edge of the
                                                           pop-up menu.

                          The following table lists the flags available to describe a pop-up menu’s behavior.
                                      Table 9.2: Flags Available to Describe a Pop-up Menu’s Behavior

                            Behavior constants                Description

                            vbPopupMenuLeftButton             Default. The pop-up menu is displayed when the
                                                              user clicks a menu item with the left mouse but-
                                                              ton only.
                            vbPopupMenuRightButton            The pop-up menu is displayed when the user clicks
                                                              a menu item with either the right or left mouse
                                                              button.

                          To specify a flag, we combine one constant from each group using the Or operator. The following
                          code displays a pop-up menu with its top border centered on a form when the user clicks a
                          command button. The pop-up menu triggers Click events for menu items that are clicked with
                          either the right or left mouse button.
                          Private Sub Command1_Click ()
                             ‘ Dimension X and Y variables.
                             Dim xloc, yloc


                             ‘ Set X and Y variables to center of form.
                             xloc = ScaleWidth / 2
                             yloc = ScaleHeight / 2

                             ‘ Display the pop-up menu.
                             PopupMenu mnuEdit, vbPopupMenuCenterAlign Or _
                             vbPopupMenuRightButton, xloc, yloc
                          End Sub


                          208                    LOVELY PROFESSIONAL UNIVERSITY
   209   210   211   212   213   214   215   216   217   218   219