以下仅作参考:
我在Win2000下调试通过
建立Form1,添加Combo1,Label1
设置Form1的ScaleMode为 3 - Pixel
设置Timer1的Interval为100 '监视间隔Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End TypePrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Rt As RECT
Dim H As Long
Dim M As POINTAPIPrivate Sub Combo1_GotFocus()
Timer1.Enabled = True '开始监视
End Sub
Private Sub Form_Load()
For i = 0 To 100
Combo1.AddItem i
Next
H = Me.TextHeight("Xyz") '获得一行文本的高度
End SubPrivate Sub Timer1_Timer() '监视鼠标
If Screen.ActiveControl.Name <> "Combo1" Then Timer1.Enabled = False '焦点不在Combo1上时停止监视鼠标
GetWindowRect Combo1.hwnd, Rt '获取Combo1的屏幕位置
GetCursorPos M '获取鼠标位置Label1 = Combo1.List(Combo1.TopIndex + (M.y - Rt.Bottom) \ H)
'得到目标文本
End Sub'以上如果对您有帮助,请加分!
我在Win2000下调试通过
建立Form1,添加Combo1,Label1
设置Form1的ScaleMode为 3 - Pixel
设置Timer1的Interval为100 '监视间隔Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End TypePrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Rt As RECT
Dim H As Long
Dim M As POINTAPIPrivate Sub Combo1_GotFocus()
Timer1.Enabled = True '开始监视
End Sub
Private Sub Form_Load()
For i = 0 To 100
Combo1.AddItem i
Next
H = Me.TextHeight("Xyz") '获得一行文本的高度
End SubPrivate Sub Timer1_Timer() '监视鼠标
If Screen.ActiveControl.Name <> "Combo1" Then Timer1.Enabled = False '焦点不在Combo1上时停止监视鼠标
GetWindowRect Combo1.hwnd, Rt '获取Combo1的屏幕位置
GetCursorPos M '获取鼠标位置Label1 = Combo1.List(Combo1.TopIndex + (M.y - Rt.Bottom) \ H)
'得到目标文本
End Sub'以上如果对您有帮助,请加分!
解决方案 »
- 看到论坛有不和的我很郁闷
- [求助]在vb中调用vc做的dll,产生错误?
- 网上在哪里可以下载vb6.0中文版呀
- 如何在文本文件的开始添加一行文本,不改变原来的内容(在线等候......)
- 还有经过几次数据导入之后,库文件莫名其妙的变的很大,ADO中怎样实现压缩?
- 关于VB调用Foxmail和VB调用IE的小题
- 怎么把程序发布成与系统无关的最终产品。。。。?
- 请教中国农历的算法。
- 请大家看看您做过没有??关于POS收银机
- 比微软的rtf控件更好的rtf控件
- ★★★☆☆☆高手请进:哪位大哥有锁死键盘鼠标(win2000系统)的控件或是有什么好的办法(锁不住ALT+CTRL+DEL也没有关系)??
- 请问如何将FORM左上角的图标弄没?
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 10
Combo1.AddItem Str(i) & "行"
Next
Combo1.ListIndex = 2
Text1.Text = Combo1.Text
Timer1.Interval = 50
End SubPrivate Sub Timer1_Timer()
Text1.Text = Combo1.ListIndex
Text2.Text = Combo1.List(Combo1.ListIndex)
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 10
Combo1.AddItem Str(i) & "行"
Next
Combo1.ListIndex = 2
Timer1.Interval = 50
Timer1.Enabled = False
End SubPrivate Sub Combo1_GotFocus()
Timer1.Enabled = True
End Sub
Private Sub Combo1_LostFocus()
Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
Text1.Text = Combo1.ListIndex
Text2.Text = Combo1.List(Combo1.ListIndex)
End Sub
选中项的文本 Combo1.List(Combo1.ListIndex)