Display a tooltip over a button using Windows Forms

后端 未结 9 1811
梦谈多话
梦谈多话 2020-11-29 17:37

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

9条回答
  •  爱一瞬间的悲伤
    2020-11-29 18:24

    The ToolTip is a single 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 programmatically, call

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

    in your code to show the tooltip, and

    MyToolTip.Hide(MyButton);
    

    to make it disappear again.

提交回复
热议问题