setting tooltip on textbox
There is a control named as tooltip. I am using it on a form. It shows me the tooltip on textbox when I bring mouse over the textbox.
Is it possible that when the textbox gets focus(using tab key) then toolip gets displayed on textbox.
Please help and guide.
Re: setting tooltip on textbox
If you want to do something with a class the first thing you should do is look at the members of that class. The Show method of the ToolTip class is described thusly:
Quote:
Overloaded. Sets the text associated with a ToolTip, and then displays it.
If you want to do something when somethign happens that means handling an event. The Enter event of a control is raised when it gets focus.
Re: setting tooltip on textbox
Add a form to ur project
Add some textboxes and a tooltip control to that form.
For Each Control Provide Tooltip Text.
Try the following Code
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Ctrl As Control
' The following code is assumed that u will directly add texboxes and
' other controls Directly on the form Not on any container
' like tabpage, groupbox
For i As Integer = 0 To Me.Controls.Count - 1
Ctrl = Me.Controls(i)
AddHandler Ctrl.GotFocus, AddressOf ShowToolTip
AddHandler Ctrl.LostFocus, AddressOf HideToolTip
Next
End Sub
Private Sub ShowToolTip(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Ctrl As Control = DirectCast(sender, Control)
ToolTip1.Show(ToolTip1.GetToolTip(Ctrl), Ctrl)
End Sub
Private Sub HideToolTip(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Ctrl As Control = DirectCast(sender, Control)
ToolTip1.Hide(Ctrl)
End Sub
End Class
Note: Displayed Tooltip info will not vanish as it normaly use to disappear when mouse is hovered on control.
Re: setting tooltip on textbox
Quote:
Originally Posted by ComITSolutions
Add a form to ur project
Add some textboxes and a tooltip control to that form.
For Each Control Provide Tooltip Text.
Try the following Code
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Ctrl As Control
' The following code is assumed that u will directly add texboxes and
' other controls Directly on the form Not on any container
' like tabpage, groupbox
For i As Integer = 0 To Me.Controls.Count - 1
Ctrl = Me.Controls(i)
AddHandler Ctrl.GotFocus, AddressOf ShowToolTip
AddHandler Ctrl.LostFocus, AddressOf HideToolTip
Next
End Sub
Private Sub ShowToolTip(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Ctrl As Control = DirectCast(sender, Control)
ToolTip1.Show(ToolTip1.GetToolTip(Ctrl), Ctrl)
End Sub
Private Sub HideToolTip(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Ctrl As Control = DirectCast(sender, Control)
ToolTip1.Hide(Ctrl)
End Sub
End Class
Note: Displayed Tooltip info will not vanish as it normaly use to disappear when mouse is hovered on control.
MSDN advises you to use the Enter and Leave events rather than GotFocus and LostFocus.
Re: setting tooltip on textbox
Thanx for the advice atheist