Svi*_*ish 152 c# tooltip winforms
我有一些控件,我想ToolTip在鼠标悬停在它上面时显示.我怎样才能做到这一点?我想知道如何在代码中正确地执行此操作,但也在设计器中(ToolTip在工具箱中有一个组件,但我不完全......得到它).
如果这是重复的话,我不会感到惊讶,但我只能找到更高级,特定场景的问题.我想知道基础知识.
Sve*_*lov 201
private void Form1_Load(object sender, System.EventArgs e)
{
// Create the ToolTip and associate with the Form container.
ToolTip toolTip1 = new ToolTip();
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(this.button1, "My button1");
toolTip1.SetToolTip(this.checkBox1, "My checkBox1");
}
Run Code Online (Sandbox Code Playgroud)
JYe*_*ton 137
将工具提示控件从工具箱拖到窗体上.你真的不需要给它任何名称以外的属性.然后,在希望有工具提示的控件属性中,查找一个新属性,其中包含刚刚添加的工具提示控件的名称.当光标悬停控件时,默认情况下会为您提供工具提示.
Fre*_*örk 39
这里的技巧是ToolTip控件是一个扩展器控件,这意味着它将扩展窗体上其他控件的属性集.在幕后,这是通过生成像Svetlozar的答案中的代码来实现的.还有其他控件以相同的方式工作(例如HelpProvider).
小智 8
C#中的ToolTip很容易添加到几乎所有的UI控件中.您无需为此添加任何MouseHover事件.
这是怎么做的 -
将ToolTip对象添加到表单.一个对象足以满足整个表单.
ToolTip toolTip = new ToolTip();
使用所需文本将控件添加到工具提示.
toolTip.SetToolTip(Button1,"Click here");
| 归档时间: |
|
| 查看次数: |
169828 次 |
| 最近记录: |