为什么没有显示指向正确控件的气球提示? [英] Why aren't balloon tips shown pointing at the correct control?

查看:20
本文介绍了为什么没有显示指向正确控件的气球提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上使用 ToolTip 控件,但发现即使我的光标位于一个控件上,工具提示也显示在其他地方.我想在我的光标所在的控件中显示这个.

如上图所示,当我的光标在 Textbox3 上时,工具提示显示在 Textbox4 上.我希望它显示为指向 Textbox3.

我目前使用以下代码在 3 个不同的事件中显示工具提示:

 private void txtImmedieddest_Enter(object sender, EventArgs e){ttpDetail.Show("Ex:111000025", txtImmedieddest);}私有无效txtImmedieddest_MouseHover(对象发送者,EventArgs e){ttpDetail.Show("Ex:111000025", txtImmedieddest);}私有无效txtImmedieddest_MouseUp(对象发送者,MouseEventArgs e){ttpDetail.Show("Ex:111000025", txtImmedieddest, e.Location);//toolTipimmeddest.Show("Required & Must be 9 Digits", txtImmedieddest);}

编辑

 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(应该是数字)", textBox1,textBox1.Width, textBox1.Height/10,5000);}

这很好用,但是当鼠标最初放在控件上时,它显示正常,如果我第二次显示正确

看下面的图片

解决方案

您看到的问题是因为您的 ToolTip 控件的 ,指定 EM_SHOWBALLOONTIP 和一个EDITBALLOONTIP 结构 包含有关工具提示的信息我想展示.我将查找适当的定义并编写包装器代码作为读者练习,因为这个答案已经太长了.

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.

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

解决方案

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.

这篇关于为什么没有显示指向正确控件的气球提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆