vb怎么实现点击鼠标右键出现菜单选项

我现在想做出 这样的效果,谁自动的 ,告诉我一下!!
2024-12-03 15:07:37
推荐回答(3个)
回答(1):

方法1:编写菜单,然后利用菜单项的:Enabled属性或者Visible属性;
方法2:建立快捷菜单;右击出现菜单。
方法1的实现简单:
在创建菜单的时候,每个菜单项有1个”标题”和”名称”,其中名称其实是该菜单项的对象的名称,例如某菜单名称叫”abc”,那么:
abc. Visible=false 就使它不可见
abc. Visible= true 就使它可见

回答(2):

工具--菜单编辑器,建立以个你需要的菜单,名称为mainmenu,visble=false Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Me.PopupMenu mainmenu
End If
End Sub
复制一下代码,窗体上右键即可看到结果

回答(3):

楼上这位大哥,人家是要托盘的菜单!菜单编辑器
'名称: Traymenu, 标题: 主菜单
'名称: menuexit, 标题: 退出
'然后把代码复制进去

Option Explicit
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Const SW_RESTORE = 9
Const SW_HIDE = 0
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private nfIconData As NOTIFYICONDATA

Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
nfIconData.cbSize = Len(nfIconData)
nfIconData.uID = vbNull
nfIconData.hwnd = Me.hwnd
nfIconData.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon
nfIconData.szTip = "测试" & vbNullChar
Shell_NotifyIcon NIM_ADD, nfIconData
Me.Hide
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = WM_LBUTTONUP Then
Me.WindowState = 0
Me.Show
Else
If lMsg = WM_RBUTTONUP Then
PopupMenu Traymenu
End If
End If
End Sub

Private Sub menuexit_Click()
End
End Sub