listview控件,在执行itemclick事件后弹出窗口,但是关闭窗口之后,控件中的项目随着鼠标的移动而移动?
主要想实现是效果是点击listview控件中的项目就弹出窗口,现在窗口是弹出来了,可是关闭窗口之后,项目就跟着鼠标动了,帮帮忙啊,大侠们!...
主要想实现是效果是点击listview控件中的项目就弹出窗口,现在窗口是弹出来了,可是关闭窗口之后,项目就跟着鼠标动了,帮帮忙啊,大侠们!
展开
展开全部
向Listview发送一个鼠标左键弹起的消息就可以了:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONUP = &H202
Private Sub Form_Load()
With ListView1
.LabelEdit = lvwManual
.ListItems.Add , , "aaa"
.ListItems.Add , , "bbb"
End With
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
If Item.Text = "aaa" Then
Form2.Show vbModal '如果form2以非模式方式显示,不会出现楼主所说的问题
'如果form2是以模式方式显示,则在鼠标左键按下时激发ItemClick事件,但Form2显示出来,Listview不会再接收鼠标左键弹起的消息,所以当form2关闭后,ListView还会“以为”左键处于按下状态,所以移动鼠标时项目就会跟着鼠标移动
'这里强制向Listview发送一个鼠标弹起的消息解除拖动状态
SendMessage ListView1.hwnd, WM_LBUTTONUP, 0, 0
End If
End Sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONUP = &H202
Private Sub Form_Load()
With ListView1
.LabelEdit = lvwManual
.ListItems.Add , , "aaa"
.ListItems.Add , , "bbb"
End With
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
If Item.Text = "aaa" Then
Form2.Show vbModal '如果form2以非模式方式显示,不会出现楼主所说的问题
'如果form2是以模式方式显示,则在鼠标左键按下时激发ItemClick事件,但Form2显示出来,Listview不会再接收鼠标左键弹起的消息,所以当form2关闭后,ListView还会“以为”左键处于按下状态,所以移动鼠标时项目就会跟着鼠标移动
'这里强制向Listview发送一个鼠标弹起的消息解除拖动状态
SendMessage ListView1.hwnd, WM_LBUTTONUP, 0, 0
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询