VB实现冒泡提示效果

Posted by Leon on 2015-10-18

这几天在做一个VB系统,突然想到可以给控件增加冒泡提示效果.

实现TextBox的冒泡提示,原理很简单,利用textbox Focus事件,弹出提示框,双击关闭。摘出代码如下:

需要界面里添加控件, rtbTip(richtextbox),txtBox(textbox)代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Private Sub txtBox_GotFocus()
Call TipText("我是冒泡提示内容,你可以自定义richtextbox样式!",txtBox)
End Sub

Private Sub rtbTip_DblClick()
rtbTip.Visible = False
End Sub

Sub TipText(txt As String, control As TextBox)
Dim tLeft#
rtbTip.Visible = False
If txt = "" Then Exit Sub
rtbTip.width = 1900
rtbTip.Height = 1000
rtbTip.Locked = True
rtbTip.Text = txt
rtbTip.ToolTipText = "双击关闭我!"
rtbTip.Top = control.Top
tLeft = control.Left + control.width
If (tLeft + rtbTip.width) > Me.width Then
tLeft = control.Left - rtbTip.width
End If
rtbTip.Left = tLeft
rtbTip.Visible = True
End Sub

PS:只能为textbox添加提示效果,你也可以稍加修改为其他控件