WinForms中的自定义工具提示控件

4

有没有一种简单的方法在C# / WinForms中创建和显示自定义工具提示控件?

我的目前想法是:

  • 创建Tooltip的子类,重写OnPaint方法,并将其设置为父控件的工具提示

  • 创建Form的子类并手动显示它

有什么想法吗?


请继续!有什么问题吗? - Sasha Reminnyi
只是想知道是否有更好的方法。 - Andy Aiken
1个回答

3

这取决于你需要的工具提示内容。如果你只需要一个带有气球形状、动画和淡入淡出效果的工具提示,以及自定义文本颜色和背景,那么使用ToolTip控件会更容易。

 // Create your control
 System.Windows.Forms.Button trialButton = new Button();
 trialButton.Text = "Trial Button";

 // Tool tip string
 string toolTipText = "Hello World";
 // ToolTip toolTip = new ToolTip(this.components);
 ToolTip toolTip = new ToolTip();
 toolTip.ToolTipTitle = "ToolTip Title";
 toolTip.UseAnimation = true;
 toolTip.UseFading = true;
 toolTip.IsBalloon = true;
 toolTip.Active = true;
 toolTip.SetToolTip(button, toolTipText);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接