VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3195 ClientLeft = 165 ClientTop = 735 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 4680 StartUpPosition = 3 '窗口缺省 Begin VB.Menu mnu_file Caption = "File" Begin VB.Menu mnu_open Caption = "Open" End Begin VB.Menu mnu_bar Caption = "-" End Begin VB.Menu mnu_exit Caption = "E&xit" End End Begin VB.Menu mnu_edit Caption = "Edit" Begin VB.Menu mnu_Copy Caption = "Copy" End Begin VB.Menu mnu_cut Caption = "Cut" End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Button Case 2 PopupMenu mnu_edit End Select End Sub
在窗体的MouseDown事件中设置代码啊!if button =2 then '2是鼠标右键 popupMenu xxx 'xxx是菜单名称 end if
上面代码保存为扩展名的.frm的文件即可
先在菜单设计器中设置菜单(如:mununame1) 然后 Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) if button =2 then '2是鼠标右键 popupMenu mununame1 end ifEnd Sub
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 165
ClientTop = 735
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.Menu mnu_file
Caption = "File"
Begin VB.Menu mnu_open
Caption = "Open"
End
Begin VB.Menu mnu_bar
Caption = "-"
End
Begin VB.Menu mnu_exit
Caption = "E&xit"
End
End
Begin VB.Menu mnu_edit
Caption = "Edit"
Begin VB.Menu mnu_Copy
Caption = "Copy"
End
Begin VB.Menu mnu_cut
Caption = "Cut"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 2
PopupMenu mnu_edit
End Select
End Sub
popupMenu xxx 'xxx是菜单名称
end if
然后
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
if button =2 then '2是鼠标右键
popupMenu mununame1
end ifEnd Sub
[email protected]
谢谢