Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Jul 24, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Display Tooltips

You can easily duplicate the tooltips that appear when you float the mouse over a button in Microsoft's products. This code displays the tooltip in the lower right-hand corner of the control (normally a button):

 ' xTip: string to display as the tip
' xCtrl: control you want the tip to show for.
' xTipControl: control being used to display 
' the tip (an SSPanel)
Public Sub ShowTip(xTip As String, xCtrl As _
	Control, xTipControl As Control)
	xTipControl.Left = xCtrl.Left + xCtrl.Width
	xTipControl.Top = xCtrl.Top + xCtrl.Height
	xTipControl.Caption = xTip
	xTipControl.Visible = True
End Sub

This code hides the tooltip:

 ' xTipControl : control which is being used to 
' display the tip.
Public Sub HideTip(xTipControl As Control)
	xTipControl.Visible = False
End Sub

Place the ShowTip function in the MouseMove event of the control(s) for which you want to display a tip. Place the HideTip function in the other control(s) for which you don't want to display a tip:

 Sub Command1_MouseMove (Button As Integer, _
	Shift As Integer, X As Single, Y As Single)
	ShowTip "Command1", Command1, SSPanel1
End Sub

Sub Command2_MouseMove (Button As Integer, _
	Shift As Integer, X As Single, Y As Single)
	ShowTip "Command2", Command2, SSPanel1
End Sub

Sub Form_MouseMove (Button As Integer, _
	Shift As Integer, X As Single, Y As Single)
'No tooltip for form
	HideTip Text1
End Sub
Andy McInturff
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date