Results 1 to 12 of 12

Thread: [RESOLVED] Dynamically adding tool-tips to controls

Threaded View

  1. #12
    New Member
    Join Date
    Nov 2024
    Posts
    1

    Re: Dynamically adding tool-tips to controls

    Quote Originally Posted by Reapism View Post
    It doesn't seem to run more than once. I have call the method on load.
    I know this thread is old and maby outdated, but someone could find this usefull.
    Code:
        Private Sub ShowTooltip(ByVal ControleName As Control, ByVal InputText As String, Optional TextLength As Integer = 40, Optional Titel As String = "Information", Optional DisplayTime As Integer = 5000)
            'Add Private TT1 as New ToolTip in top of Class (Under the classname), to make it work as a form all over tooltip
            Dim ActiveText As String = InputText
            Dim Output As String = String.Empty
            Dim PartOfstring As String = String.Empty
    
            While ActiveText.Length > 1
                If ActiveText.Length < TextLength Then
                    Output &= ActiveText
                    ActiveText = String.Empty
                Else
                    Dim SpaceBar As Integer = 0
                    SpaceBar = InStr(Mid(ActiveText, TextLength, ActiveText.Length), " ")
                    PartOfstring = Mid(ActiveText, 1, TextLength + (SpaceBar - 1)) & Environment.NewLine
                    Output &= PartOfstring
                    ActiveText = Mid(ActiveText, TextLength + SpaceBar, ActiveText.Length)
                End If
            End While
    
            TT1.ToolTipTitle = Titel
            TT1.AutoPopDelay = DisplayTime
            TT1.Show(Output, ControleName)
        End Sub
    You will use it as this example:
    Code:
        Private Sub Lbl_Besked_MouseHover(sender As Object, e As EventArgs) Handles Lbl_Besked.MouseHover
            ShowTooltip(Lbl_Besked, Lbl_Besked.Text,, "Test Info")
        End Sub
    I know you have to write it in all form elements you wanna show tooltip on, but it is working as it should. Use it as an idea or leave it.
    Last edited by Shaggy Hiker; Nov 7th, 2024 at 11:23 AM. Reason: Added CODE tags.

Tags for this Thread

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