求助VB大神,TextBox怎么在Listview的MouseDown的事件中获得焦点(或全选)?
在以下代码中,单击ListView1后text1没能全选。PrivateSubListView1_MouseDown(ButtonAsInteger,ShiftAsInt...
在以下代码中,单击ListView1后text1没能全选。
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'其它代码
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub 展开
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'其它代码
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub 展开
1个回答
展开全部
这样
Text1.SelLength = Len(Text1.Text) ====== 这里
亲
Text1.SelLength = Len(Text1.Text) ====== 这里
亲
追问
和这个没关系,Len(Text1.Text) 和Len(Text1) 一样,只不过不规范。如果是对label的MouseDown就没问题。但ListView却不行。
追答
失误了,控件默认属性值 确实
要api PostMessage发送消息实现, 因为 listview1的mousedown是由于listview得到了
鼠标输入焦点 并且 在mousedown结束前输入焦点不会离开他,
so解决方案 在mousedown事件 PostMessage给 text1的消息队列 发送 EM_SETSEL和WM_SETFOCUS两个消息
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const EM_SETSEL As Long = &HB1
Const WM_SETFOCUS As Long = &H7
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
PostMessage Text1.hwnd, EM_SETSEL, 0, Len(Text1.Text)
PostMessage Text1.hwnd, WM_SETFOCUS, ListView1.hwnd, 0
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询