当我设置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 上运行。
最佳答案
到目前为止,我发现的最佳解决方法是调用 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);
}
希望有比这更好的东西。
堆栈溢出问题 Windows Forms ToolTip will not re-appear after first use 听起来有点相似,并提到 the bug ToolTip balloon flickers position using Show method Microsoft 似乎对修复不感兴趣。
关于c# - IsBalloon 属性使 Windows 窗体工具提示位置不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6657572/