Results 1 to 5 of 5

Thread: setting tooltip on textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    237

    Angry 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.
    software engineer

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    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.
    Last edited by ComITSolutions; Feb 26th, 2008 at 09:13 AM. Reason: Code tags added

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    Re: setting tooltip on textbox

    Thanx for the advice atheist

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width