简体   繁体   English

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

[英]Custom tooltip control in WinForms

Is there a simple way to create and show a custom tooltip control in C# / WinForms? 有没有一种简单的方法来在C#/ WinForms中创建和显示自定义工具提示控件?

My current thinking is either: 我目前的想法是:

  • create a subclass of Tooltip, override the OnPaint method, set it as the parent control's tooltip 创建Tooltip的子类,重写OnPaint方法,将其设置为父控件的工具提示

  • create a subclass of form and show it manually 创建表单的子类并手动显示它

Any thoughts? 有什么想法吗?

It depends on what you need for your tool tip. 这取决于您的工具提示所需的内容。 If you only need a tool tip with balloon shape, animation and fading effects with custom text color and background, It is easier to use ToolTip control 如果您只需要具有气球形状的工具提示,具有自定义文本颜色和背景的动画和淡化效果,则使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM