Display a tooltip over a button using Windows Form

2019-01-07 04:42发布

How can I display a tooltip over a button using Windows Forms?

8条回答
太酷不给撩
2楼-- · 2019-01-07 05:23

Using the form designer:

  • Drag the ToolTip control from the Toolbox, onto the form.
  • Select the properties of the control you want the tool tip to appear on.
  • Find the property 'ToolTip on toolTip1' (the name may not be toolTip1 if you changed it's default name).
  • Set the text of the property to the tool tip text you would like to display.

You can set also the tool tip programatically using the following call:

this.toolTip1.SetToolTip(this.targetControl, "My Tool Tip");
查看更多
Melony?
3楼-- · 2019-01-07 05:27

The ToolTip is actually a WinForms control that handles displaying tool tips for multiple elements on a single form.

Say your button is called MyButton.

  1. Add a ToolTip control (under Common Controls in the Windows Forms toolbox) to your form.
  2. Give it a name - say MyToolTip
  3. Set the "Tooltip on MyToolTip" property of MyButton (under Misc in the button property grid) to the text that should appear when you hover over it.

The tooltip will automatically appear when the cursor hovers over the button, but if you need to display it programatically, call

MyToolTip.Show("Tooltip text goes here", MyButton)

in your code to show the tooltip, and MyToolTip.Hide(MyButton) to make it disappear again.

查看更多
登录 后发表回答