Results 1 to 9 of 9

Thread: tooltip no longer working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    tooltip no longer working

    Hi All.. I am creating buttons dynamically from a delimited text file and assigning text to a tooltip. This was always working just fine, but for some reason all of a sudden they stopped working. I have not done anything strange with the tooltip so I cannot explain how it happened. What seems so basic has totally stopped on me. Here is how I am creating the tooltips:

    Code:
    Dim myDefectFile As String
            myDefectFile = Environment.CurrentDirectory & "\Defect_Files\"
    
            Dim FILE_NAME As String = myDefectFile & "Defects.txt"
            Dim data() As String
    
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
    
            Do While objReader.Peek() <> -1
                rawData = objReader.ReadLine()
                data = Split(rawData, ",")
    
                If data(0) = ToggleFile Then
                    Dim dynamicButton As New Button With {
                        .Location = New Point(CInt(data(2)), CInt(data(3))),
                        .Height = 5,
                        .Width = 5,
                        .FlatStyle = FlatStyle.Flat,
                        .BackColor = Color.Magenta,
                        .ForeColor = Color.Magenta
                    }
    
                    If PictureBox1.Visible = True Then
                        PictureBox1.Select()
                        Me.PictureBox1.Controls.Add(dynamicButton)
                    ElseIf PictureBox2.Visible = True Then
                        PictureBox2.Select()
                        Me.PictureBox2.Controls.Add(dynamicButton)
                    End If
    
                    Dim tip As New ToolTip
                    Dim myToolTipText = "SN:" & data(1) & " '" & data(6) & "'"
    
                    tip.SetToolTip(dynamicButton, myToolTipText)
                    TextBox1.Text = "DEFECT MAP"
    
                End If
    
            Loop

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: tooltip no longer working

    There are a couple of things that come to mind:
    1. The data has changed. Perhaps there is an unescaped comma (which aren't being handled) or less columns and it is causing some sort of indexing error when you get the value of data by its index.
    2. The button is never being added to PictureBox1 or PictureBox2 because the If/Then statements are being reached
    3. I know that PictureBox inherits Control and Control has a Controls property, but I didn't think you could add controls to a PictureBox (though I may be wrong)


    You should set a breakpoint up where you check the visibility of PictureBox1, then step through your code to make sure that the right workflow is occurring.

    By the way, I'm not sure what version of Visual Studio you're using, but you could modify your code to:
    Code:
    Dim filename = IO.Path.Combine(Environment.CurrentDirectory, "Defect_Files", "Defects.txt")
    If (IO.File.Exists(filename) Then
        Dim lines = IO.File.ReadAllLines(filename)
        For Each line In lines
            Dim cells = line.Split(","c)
    
            If (cells.Length > 0 AndAlso cells(0) = ToggleFile) Then
                TextBox1.Text = "DEFECT MAP"
                Dim dynamicButton As New Button With {
                    .Location = New Point(CInt(data(2)), CInt(data(3))),
                    .Height = 5,
                    .Width = 5,
                    .FlatStyle = FlatStyle.Flat,
                    .BackColor = Color.Magenta,
                    .ForeColor = Color.Magenta
                }
    
                If (data.Length > 6) Then
                    Dim tip = New ToolTip()
                    tip.SetToolTip(dynamicButton, $"SN: {data(0)} '{data(6)}'")
                End If
    
                If PictureBox1.Visible = True Then
                    PictureBox1.Select()
                    Me.PictureBox1.Controls.Add(dynamicButton)
                ElseIf PictureBox2.Visible = True Then
                    PictureBox2.Select()
                    Me.PictureBox2.Controls.Add(dynamicButton)
                End If
            End If
        Next
    End If
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Re: tooltip no longer working

    Thanks for this.. I did update my code to your suggestion. So I am getting my dynamic buttons added to the picturebox when expected, so the data points from the file seem to be ok there. I am returning a msgbox with my tooltip text that should be showing at the time of adding the button and that seems to work ok. But no matter what I do, that tooltip doesn't want to actually show when I hover over any of the buttons. The only thing left is the breakpoint you mentioned, which I am not certain how to setup.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: tooltip no longer working

    If you place your cursor on the line you want to setup the breakpoint and hit F9, it will add it for you (the line will be highlighted red). F9 is how you toggle breakpoints.

    Once you're running the code, the code will "break" (aka - pause, stop, etc.) at your breakpoint. From here you can open the watch window, add variables to the watch list, and inspect what they are.

    If you hit F10 while in break mode, the code will step over 1 line. In other words, it will execute the line without going into any methods (if applicable).

    If you hit F11 while in break mode, the code will step into line. in other words, if the current line is a method, then it will bring you inside of the method.

    None of your lines are referencing methods, so you should be good with doing F10, one line at a time, inspecting the variables as you go.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Re: tooltip no longer working

    Thanks dday9, but I am totally lost with this. I ran the breakpoint and followed a couple of variables that it would allow me to, but nothing really seems to point out the problem with the tooltip. I can return the tooltip text through a msgbox, button shows up just as it should but no tooltip popup will exist. ugh..

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: tooltip no longer working

    Don't be creating a new ToolTip component for every Button. You don't need any more than one TooTip on the whole form. Add one ToolTip to the form in the designer, then call SetToolTip on that for each Button.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Re: tooltip no longer working

    ok... so this has been quite a learning experience for me. I just realized that I had my picturebox disabled, which is what my buttons are being created on. I commented this out to try it and magic, the tooltip shows. However, I found on the Microsoft site that if you have ShowAlways set to true, the tooltip will show over a disabled control. This does not seem to be the case, unless there is another piece I am missing.

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: tooltip no longer working

    If the BUTTON had been disabled, it may have worked... but because the picture box, which is the container, was disabled, the message never gets through, so the ShowAlways doesn't happen.
    By disabling the container, you effectively pulled the wool over the eyes of Windows to allow it to see that there were buttons on it that had tooltips.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Re: tooltip no longer working

    Thanks techgnome.. I have not yet found a way around this, so in the meantime I have made a small workaround not related to this method at all.

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