How do I create a tooltip programatically for a programaticallygenerated label

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Mad Ape

    How do I create a tooltip programatically for a programaticallygenerated label

    Hi

    I have code to programatically create a label. It works but when I try
    to call a sub to create a tooltip it does not work. I do not get an
    error so have no idea what it wrong. Please review my code and tell me
    how to fix it.

    Thanks

    The Mad Ape


    CODE TO CREATE LABEL:

    Dim tabLblPulp As New Label
    tabLblPulp.Loca tion = New Point(14, 121)
    tabLblPulp.Size = New Size(54, 13)
    tabLblPulp.Name = tp.Text & "lblPulpwoo d"
    tabLblPulp.Text = "Pulpwood"
    tabLblPulp.Fore Color = Color.Blue
    tabLblPulp.Visi ble = True
    tabLblPulp.Font = New System.Drawing. Font("Microsoft
    Sans Serif", 8.25!, System.Drawing. FontStyle.Under line,
    System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
    tp.Controls.Add (tabLblPulp)

    'code to call sub

    AddHandler tabLblPulp.Clic k, AddressOf ToolTiper

    Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)

    Dim ctrlName As String
    ctrlName = DirectCast(send er, Control).Name()
    Dim ToolTip2 As New ToolTip
    Dim ctrl As Control
    For Each ctrl In Form7.Controls
    If ctrl.Name = ctrlName Then
    ToolTip2.SetToo lTip(ctrl, "Test")
    End If
    Next

    End Sub
  • Steve Gerrard

    #2
    Re: How do I create a tooltip programatically for a programatically generated label

    The Mad Ape wrote:
    Hi
    >
    I have code to programatically create a label. It works but when I try
    to call a sub to create a tooltip it does not work. I do not get an
    error so have no idea what it wrong. Please review my code and tell me
    how to fix it.
    >
    What's wrong: Form7.Controls will contain only the controls that are directly on
    the form, such as a tab control. The tab control itself will contain the tab
    pages; one tab page will in turn contain controls that are on it, such as a
    label. So your hunt through Form7.Controls never finds the control in question.

    How to fix it: You have a DirectCast to Control, using the sender of your event.
    Guess what? That's the control you want. There is no need to get its name, then
    go try and find it in a control collection somewhere. You already have it.

    Just do
    ctrl = DirectCast(send er, ctrl)
    ToolTip2.SetToo lTip(ctrl, "Test")


    Comment

    • The Mad Ape

      #3
      Re: How do I create a tooltip programatically for a programatically generated label

      On Apr 6, 9:12 pm, "Steve Gerrard" <mynameh...@com cast.netwrote:
      The Mad Ape wrote:
      Hi
      >
      I have code to programatically create a label. It works but when I try
      to call a sub to create a tooltip it does not work. I do not get an
      error so have no idea what it wrong. Please review my code and tell me
      how to fix it.
      >
      What's wrong: Form7.Controls will contain only the controls that are directly on
      the form, such as a tab control. The tab control itself will contain the tab
      pages; one tab page will in turn contain controls that are on it, such as a
      label. So your hunt through Form7.Controls never finds the control in question.
      >
      How to fix it: You have a DirectCast to Control, using the sender of your event.
      Guess what? That's the control you want. There is no need to get its name, then
      go try and find it in a control collection somewhere. You already have it.
      >
      Just do
      ctrl = DirectCast(send er, ctrl)
      ToolTip2.SetToo lTip(ctrl, "Test")
      Hi

      I tried the following:

      Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)

      Dim ToolTip2 As New ToolTip
      Dim ctrl As Control
      ctrl = DirectCast(send er, Control)
      ToolTip2.SetToo lTip(ctrl, "Test")

      End Sub

      Still nothing. No error but no tool tip either. I am totally confused
      now. I am using VB.Net from VS 2005 SP2. Any ideas? This control does
      reside on a tabpage if that means anything.

      I would appreciate any help you could provide.

      Thanks

      Comment

      • Jack Jackson

        #4
        Re: How do I create a tooltip programatically for a programatically generated label

        On Sun, 6 Apr 2008 17:34:44 -0700 (PDT), The Mad Ape
        <chiefape@gmail .comwrote:
        >On Apr 6, 9:12 pm, "Steve Gerrard" <mynameh...@com cast.netwrote:
        >The Mad Ape wrote:
        Hi
        >>
        I have code to programatically create a label. It works but when I try
        to call a sub to create a tooltip it does not work. I do not get an
        error so have no idea what it wrong. Please review my code and tell me
        how to fix it.
        >>
        >What's wrong: Form7.Controls will contain only the controls that are directly on
        >the form, such as a tab control. The tab control itself will contain the tab
        >pages; one tab page will in turn contain controls that are on it, such as a
        >label. So your hunt through Form7.Controls never finds the control in question.
        >>
        >How to fix it: You have a DirectCast to Control, using the sender of your event.
        >Guess what? That's the control you want. There is no need to get its name, then
        >go try and find it in a control collection somewhere. You already have it.
        >>
        >Just do
        > ctrl = DirectCast(send er, ctrl)
        > ToolTip2.SetToo lTip(ctrl, "Test")
        >
        >Hi
        >
        >I tried the following:
        >
        Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)
        >
        Dim ToolTip2 As New ToolTip
        Dim ctrl As Control
        ctrl = DirectCast(send er, Control)
        ToolTip2.SetToo lTip(ctrl, "Test")
        >
        End Sub
        >
        >Still nothing. No error but no tool tip either. I am totally confused
        >now. I am using VB.Net from VS 2005 SP2. Any ideas? This control does
        >reside on a tabpage if that means anything.
        >
        >I would appreciate any help you could provide.
        >
        >Thanks
        Your code works for me. Is ToolTiper() being called?

        Comment

        • Steve Gerrard

          #5
          Re: How do I create a tooltip programatically for a programatically generated label

          The Mad Ape wrote:
          I am creating the label and using Add Handler. Doesn't the Add Handler
          statement call ToolTiper?
          >
          >
          AddHandler tabLblPulp.Clic k, AddressOf ToolTiper
          >
          No, it just sets it up to handle tabLblPulp.Clic k events. It would get called
          when you click on the label.

          Based on your misunderstandin g, you probably don't want or need the code in the
          label click event. That would mean it didn't have a tooltip at first; if you
          click it, then it will have one after.

          You may just want to put those lines after you have finished making the label:
          ' ....
          tp.Controls.Add (tabLblPulp)

          ' now just add the tooltip to it

          Dim ToolTip2 As New ToolTip
          ToolTip2.SetToo lTip(tabLblPulp , "Test")

          The tooltip object itself handles the display of the tooltip when the user
          hovers over the label a certain amount of time, and all the other behavior of
          it.


          Comment

          • The Mad Ape

            #6
            Re: How do I create a tooltip programatically for a programatically generated label

            On Apr 7, 11:14 pm, "Steve Gerrard" <mynameh...@com cast.netwrote:
            The Mad Ape wrote:
            I am creating the label and using Add Handler. Doesn't the Add Handler
            statement call ToolTiper?
            >
            AddHandler tabLblPulp.Clic k, AddressOf ToolTiper
            >
            No, it just sets it up to handle tabLblPulp.Clic k events. It would get called
            when you click on the label.
            >
            Based on your misunderstandin g, you probably don't want or need the code in the
            label click event. That would mean it didn't have a tooltip at first; if you
            click it, then it will have one after.
            >
            You may just want to put those lines after you have finished making the label:
            ' ....
            tp.Controls.Add (tabLblPulp)
            >
            ' now just add the tooltip to it
            >
            Dim ToolTip2 As New ToolTip
            ToolTip2.SetToo lTip(tabLblPulp , "Test")
            >
            The tooltip object itself handles the display of the tooltip when the user
            hovers over the label a certain amount of time, and all the other behavior of
            it.
            When I first wrote this code, this is what I did. And when it did not
            work I branched out into the sub and handler. I tried it again and it
            still does not work. So in an effort to find out what is going on I
            added a label to the tab and referenced it in the tool tip code that
            you suggested. It works so the problem lies in the wiring between the
            code used to create the label and the code to create the tool tip.

            Next I wrote the code to add a new label to the form and it works. So
            the problem appears to be when I attempt to add the tooltip to a
            control on a tab.

            Would this be a, as yet, undiscovered bug in VB.net or is there a
            missing step because of the tab?

            Thanks

            Comment

            • The Mad Ape

              #7
              Re: How do I create a tooltip programatically for a programatically generated label

              I re-read my last response and I think I need to be more clear as to
              what is going on.

              1) I can programatically create a label and programatically add a tool
              tip to that label when the label is on a form.
              2) I can programatically create a tool tip for an already existing
              label on a tab page
              3) I can programatically create a label on a tab page but the same
              code used in #1 to programatically create a tool tip does not work and
              I don't know why.

              Comment

              • The Mad Ape

                #8
                Re: How do I create a tooltip programatically for a programatically generated label

                On Apr 8, 8:07 am, The Mad Ape <chief...@gmail .comwrote:
                I re-read my last response and I think I need to be more clear as to
                what is going on.
                >
                1) I can programatically create a label and programatically add a tool
                tip to that label when the label is on a form.
                2) I can programatically create a tool tip for an already existing
                label on a tab page
                3) I can programatically create a label on a tab page but the same
                code used in #1 to programatically create a tool tip does not work and
                I don't know why.
                Finally after 3 days I have found the problem. Prior to creating the
                label and tooltip I had code to create a rectangle and some lines
                using Visual Basic Power Pack 3.0. If you draw the lines first they
                hide the tool tip and cursor settings. If you add the lines after the
                tooltip and cursor have been added then it will work. Sort of works in
                reverse logic.

                I thank you guys for helping through this very frustrating experience.
                Now I can go forward with this project.

                The Mad Ape

                Comment

                Working...