会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
博客园
首页
新随笔
联系
订阅
管理
带有ToolTip的ListBox
Code
1
Private
Sub ListBox1_MouseMove()
Sub
ListBox1_MouseMove(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
ListBox1.MouseMove
2
Dim
MousePositionInClientCoords
As
Point
=
Me
.ListBox1.PointToClient(
Me
.MousePosition)
3
Dim
indexUnderTheMouse
As
Integer
=
Me
.ListBox1.IndexFromPoint(MousePositionInClientCoords)
4
If
indexUnderTheMouse
>
-
1
Then
5
Dim
s
As
String
=
Me
.ListBox1.Items(indexUnderTheMouse).ToString
6
Dim
g
As
Graphics
=
Me
.ListBox1.CreateGraphics
7
If
g.MeasureString(s,
Me
.ListBox1.Font).Width
>
Me
.ListBox1.ClientRectangle.Width
Then
8
Me
.ToolTip1.SetToolTip(
Me
.ListBox1, s)
9
Else
10
Me
.ToolTip1.SetToolTip(
Me
.ListBox1,
""
)
11
End
If
12
g.Dispose()
13
End
If
14
End Sub
15
或者
Code
1
Private
Sub ListBox1_MouseMove()
Sub
ListBox1_MouseMove(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
ListBox1.MouseMove
2
Dim
MousePositionInClientCoords
As
Point
=
New
Point(e.X, e.Y)
3
Dim
indexUnderTheMouse
As
Integer
=
Me
.ListBox1.IndexFromPoint(MousePositionInClientCoords)
4
If
indexUnderTheMouse
>
-
1
Then
5
Dim
s
As
String
=
Me
.ListBox1.Items(indexUnderTheMouse).ToString
6
Dim
g
As
Graphics
=
Me
.ListBox1.CreateGraphics
7
If
g.MeasureString(s,
Me
.ListBox1.Font).Width
>
Me
.ListBox1.ClientRectangle.Width
Then
8
Me
.ToolTip1.SetToolTip(
Me
.ListBox1, s)
9
Else
10
Me
.ToolTip1.SetToolTip(
Me
.ListBox1,
""
)
11
End
If
12
g.Dispose()
13
End
If
14
End Sub
posted @
2009-07-16 16:22
灰毛毛
阅读(
488
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告