'定位弹出式菜单  共2个form
'frmMain.frm   设置为启动
VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "定位弹出式菜单"
   ClientHeight    =   3300
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6300
   LinkTopic       =   "Form1"
   ScaleHeight     =   3300
   ScaleWidth      =   6300
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton btnAlign 
      Caption         =   "控件下面"
      Height          =   375
      Left            =   4800
      TabIndex        =   3
      Top             =   240
      Width           =   1335
   End
   Begin VB.CommandButton btnRight 
      Caption         =   "右边"
      Height          =   375
      Left            =   3240
      TabIndex        =   2
      Top             =   240
      Width           =   1335
   End
   Begin VB.CommandButton btnMiddle 
      Caption         =   "中间"
      Height          =   375
      Left            =   1680
      TabIndex        =   1
      Top             =   240
      Width           =   1335
   End
   Begin VB.CommandButton btnLeft 
      Caption         =   "左边"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   1335
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Popupmenu's use x/y coords to determine where to place
' the menu. In order to align the menu correctly we must
' determine what those x/y coords are.' to align to the left side of our form we use
' frmMain.ScaleLeft, to align with the right side we use
' frmMain.ScaleWidth, to align center we divide the
' ScaleWidth and ScaleHeight by 2.' Notice that the alignment doesn't change when resizing
' your form.' To align to a button you simply state that the menu's
' x location is equal to btnAlign.Left. Once we have the
' x coord we need to get the y coordinate. We then combine
' btnAlign's Height and Top to get the menu to align along
' the bottom of the button.Private Sub btnAlign_Click()
PopupMenu frmMenu.mnuFile, 0, btnAlign.Left, btnAlign.Top + btnAlign.Height
End SubPrivate Sub btnLeft_Click()
PopupMenu frmMenu.mnuFile, 0, frmMain.ScaleLeft, frmMain.ScaleHeight / 2
End SubPrivate Sub btnMiddle_Click()
PopupMenu frmMenu.mnuFile, 0, frmMain.ScaleWidth / 2, frmMain.ScaleHeight / 2
End SubPrivate Sub btnRight_Click()
PopupMenu frmMenu.mnuFile, 0, frmMain.ScaleWidth, frmMain.ScaleHeight / 2
End Sub
'frmMenu.frm
VERSION 5.00
Begin VB.Form frmMenu 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.Menu mnuFile 
      Caption         =   "File"
      Begin VB.Menu mnuAbout 
         Caption         =   "About"
      End
      Begin VB.Menu mnuContactScam 
         Caption         =   "Contact Scam"
      End
      Begin VB.Menu mnuBreak 
         Caption         =   "-"
      End
      Begin VB.Menu mnuExit 
         Caption         =   "Exit"
      End
   End
End
Attribute VB_Name = "frmMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub mnuAbout_Click()
    MsgBox "Hello1"
End SubPrivate Sub mnuContactScam_Click()
    MsgBox "Hello2"
End SubPrivate Sub mnuExit_Click()
    Unload frmMain
    Unload Me
    End
End Sub