Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't balloon tips shown pointing at the correct control?

I am using a ToolTip control on my form, but have discovered that even though my cursor is on one control, the tooltip is showing somewhere else. I would like to show this within the control my cursor is on.

alt text

As shown in the image above, when my cursor is over Textbox3, the tooltip is showing on Textbox4. I would like for it to be displayed pointing at Textbox3.

I'm currently using the following code to display the tooltip in 3 different events:

 private void txtImmediateddest_Enter(object sender, EventArgs e)
 {
     ttpDetail.Show("Ex:111000025", txtImmediateddest);
 }

 private void txtImmediateddest_MouseHover(object sender, EventArgs e)
 {
     ttpDetail.Show("Ex:111000025", txtImmediateddest);
 }

  private void txtImmediateddest_MouseUp(object sender, MouseEventArgs e)
  {
      ttpDetail.Show("Ex:111000025", txtImmediateddest, e.Location);
      //toolTipimmeddest.Show("Required & Must be 9 Digits", txtImmediateddest);
  }

Edit

 private void textBox1_MouseHover(object sender, EventArgs e)
    {
        ttpDetail.AutoPopDelay = 2000;
        ttpDetail.InitialDelay = 1000;
        ttpDetail.ReshowDelay = 500;
        ttpDetail.IsBalloon = true;
        //ttpDetail.SetToolTip(textBox1, "Ex:01(Should be Numeric)");
        ttpDetail.Show("Ex : 01(Should Be Numeric)", textBox1,textBox1.Width, textBox1.Height/10,5000);
    }

This works fine but when the mouse initially on to the control it is displaying the normal if i had for second time it is displaying correctly

Look at the following images

alt text

alt text

like image 639
Developer Avatar asked Jan 10 '11 10:01

Developer


1 Answers

The problem you're seeing is because your ToolTip control's IsBalloon property is set to "True". With this property set, the ToolTip doesn't change its relative location, causing the balloon's arrow to point to the wrong control.

Here's a side-by-side comparison demonstrating this phenomenon:

        

The simple fix, obviously, is to disable the IsBalloon property by setting it to "False". The control will revert to displaying a standard, rectangular tooltip window, which will look correctly aligned.

If that's not acceptable to you, then you will have to specify the exact location where you want the tooltip balloon to appear. Unfortunately, it looks like there's a bug in the ToolTip control that causes it not to appear properly the first time it is attached to a control. This can generally be fixed by calling the Show method with an empty string once. For example, using the following code:

private void txtImmediateddest_Enter(object sender, EventArgs e)
{
    ttpDetail.Show(string.Empty, textBox3, 0);
    ttpDetail.Show("Ex:111000025", textBox3, textBox3.Width / 2, textBox3.Height, 5000);
}

produces this result:

  

Of course, your luck may vary going this route, as well. I generally don't use the built-in ToolTip control for edit controls (such as textboxes and comboboxes). I find it's much more reliable to P/Invoke SendMessage, specifying EM_SHOWBALLOONTIP and an EDITBALLOONTIP structure containing information about the tooltip that I want to show. I'll leave looking up the appropriate definitions and writing the wrapper code as an exercise for the reader, as this answer is much too long already.

like image 160
Cody Gray Avatar answered Nov 03 '22 01:11

Cody Gray