IsBalloon 属性使 Windows 窗体工具提示位置不一致

发布于 2024-11-19 16:23:14 字数 2752 浏览 1 评论 0原文

当我设置 ToolTip 控件的 IsBalloon 属性,然后使用 ToolTip.Show() 方法显示它时,气球的尾部不显示并不总是指向我请求的位置。似乎我第一次调用 Show() 时,工具提示控件的左上角出现在我请求的位置,并且气球尾部朝下。如果我在工具提示消失之前再次调用 Show(),那么它会重新出现在我要求的位置。

是否有一些设置可以使位置更加一致?如果可能的话我想保留气球风格。

这是一个演示失败的代码示例。我要求它指向文本框的左上角。

using System;
using System.Windows.Forms;

public class Form1 : Form
{
    const int TIP_X = 50;
    const int TIP_Y = 100;

    private void button1_Click(object sender, EventArgs e)
    {
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.button1 = new System.Windows.Forms.Button();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();

        this.button1.Location = new System.Drawing.Point(50, 50);
        this.textBox1.Location = new System.Drawing.Point(TIP_X, TIP_Y);
        this.toolTip1.IsBalloon = true;

        this.button1.Click += new System.EventHandler(this.button1_Click);
        this.groupBox1.Controls.Add(this.textBox1);
        this.groupBox1.Controls.Add(this.button1);
        this.groupBox1.Location = new System.Drawing.Point(10, 10);
        this.groupBox1.Size = new System.Drawing.Size(200, 200);
        this.Controls.Add(this.groupBox1);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);

    }

    public Form1()
    {
        InitializeComponent();
    }

    private Button button1;
    private GroupBox groupBox1;
    private TextBox textBox1;
    private ToolTip toolTip1;

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
}

我试图通知用户他们可能感兴趣的内容,但他们可以安全地忽略它。我认为气球通知效果很好,因为它可以指向我告诉用户的用户界面中的特定内容。

我使用的是 Visual Studio 2008,在 Windows XP 下的 .NET 3.5 上运行。

When I set the IsBalloon property of a ToolTip control, and then use the ToolTip.Show() method to display it, the balloon's tail doesn't always point at the location I request. It seems like the first time I call Show(), the tooltip control appears with its top-left corner in the location I requested, and the balloon tail pointing down. If I call Show() again before the tooltip fades, then it reappears in the position I asked for.

Is there some setting that will make the position more consistent? I'd like to keep the balloon style if possible.

Here's a code sample that will demonstrate the failure. I'm asking for it to point at the top-left corner of the text box.

using System;
using System.Windows.Forms;

public class Form1 : Form
{
    const int TIP_X = 50;
    const int TIP_Y = 100;

    private void button1_Click(object sender, EventArgs e)
    {
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.button1 = new System.Windows.Forms.Button();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();

        this.button1.Location = new System.Drawing.Point(50, 50);
        this.textBox1.Location = new System.Drawing.Point(TIP_X, TIP_Y);
        this.toolTip1.IsBalloon = true;

        this.button1.Click += new System.EventHandler(this.button1_Click);
        this.groupBox1.Controls.Add(this.textBox1);
        this.groupBox1.Controls.Add(this.button1);
        this.groupBox1.Location = new System.Drawing.Point(10, 10);
        this.groupBox1.Size = new System.Drawing.Size(200, 200);
        this.Controls.Add(this.groupBox1);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);

    }

    public Form1()
    {
        InitializeComponent();
    }

    private Button button1;
    private GroupBox groupBox1;
    private TextBox textBox1;
    private ToolTip toolTip1;

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
}

I'm trying to notify the user of something they might be interested in, but they can safely ignore it. I thought that a balloon notification would work well, since it can point to something specific in the user interface that I'm telling the user about.

I'm using Visual Studio 2008, running on .NET 3.5 under Windows XP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-11-26 16:23:14

到目前为止,我发现的最佳解决方法是仅调用 Show() 方法两次:

    private void button1_Click(object sender, EventArgs e)
    {
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
    }

希望有比这更好的方法。

Stack Overflow 问题首次使用后 Windows 窗体工具提示将不会重新出现听起来有点相似,并提到使用 Show 方法的工具提示气球位置闪烁的 bug 微软似乎没有兴趣修复。

So far, the best workaround I've found is to just call the Show() method twice:

    private void button1_Click(object sender, EventArgs e)
    {
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
        toolTip1.Show("Test", groupBox1, TIP_X, TIP_Y, 5000);
    }

Hopefully, there's something nicer than that.

Stack Overflow question Windows Forms ToolTip will not re-appear after first use sounds vaguely similar, and mentions the bug ToolTip balloon flickers position using Show method that Microsoft doesn't seem interested in fixing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文