Custom tooltip control in WinForms

2019-02-23 18:39发布

Is there a simple way to create and show a custom tooltip control in C# / WinForms?

My current thinking is either:

  • create a subclass of Tooltip, override the OnPaint method, set it as the parent control's tooltip

  • create a subclass of form and show it manually

Any thoughts?

1条回答
Bombasti
2楼-- · 2019-02-23 19:16

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

 // 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);
查看更多
登录 后发表回答