这是我定义的弹出菜单,为什么不能使用?
换成form_mouseup,mshflexgrid1_load 都没有问题,换成datagrid就不行了,请问是为什么?
Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu MDIForm1.OutMenu
End Sub
换成form_mouseup,mshflexgrid1_load 都没有问题,换成datagrid就不行了,请问是为什么?
Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu MDIForm1.OutMenu
End Sub
If Button = vbRightButton Then PopupMenu MDIForm1.OutMenu
End Sub试试??
1。用左键随便点击一下datagrid,然后再用右键点击就有效了
2。右击之前先用DataGrid1.SetFocus,然后再用右键点击就有效了上面两种方法都是先让datagrid获得焦点再操作,下面这种在datagrid没有焦点的时候也有效::'使用子类:
'模块中:Public Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONUP = &H205Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic prevWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONUP Then Form1.Print "ok"
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End Function'
程序中
'程序中:
Private Sub Form_Load()
prevWndProc = GetWindowLong(DataGrid1.hWnd, GWL_WNDPROC)
SetWindowLong DataGrid1.hWnd, GWL_WNDPROC, AddressOf WndProc
End Sub
换成datagrid1_mousedown()则可以使用了,不明白为什么了?能不能说明一下?
lsftest() 谢谢你的方法,我会试一试。
If Button = vbRightButton Then MsgBox "ok"
End Sub
---------------这个就行了,我试过了。