看起来Label
没有Hint
或ToolTip
或Hovertext
属性。那么当鼠标靠近Label
时,首选方法是显示提示,工具提示还是悬停文本?如何将提示或工具提示添加到C#Winforms中的标签?
回答
您必须首先将ToolTip
控件添加到您的表单中。然后,您可以设置它应该为其他控件显示的文本。
这里是展示设计者的截图添加ToolTip
控制被命名为toolTip1
后:
哇,这似乎令人费解/违反直觉,Yuck。 – 2012-03-19 19:29:43
@ClayShannon以某种方式,我想它是。但设计有点优雅。一些控件永远不会需要工具提示。这样,'ToolTip'控件可以为鼠标悬停事件注册自己,并根据引发的事件显示正确的文本。这一切都发生在后台。 – Yuck 2012-03-19 19:37:21
我同意。它还允许您为多个控件使用相同的工具提示控件。 – 2015-07-12 18:55:58
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(Label1, "Label for Label1");
yourToolTip = new ToolTip();
//The below are optional, of course,
yourToolTip.ToolTipIcon = ToolTipIcon.Info;
yourToolTip.IsBalloon = true;
yourToolTip.ShowAlways = true;
yourToolTip.SetToolTip(lblYourLabel,"Oooh, you put your mouse over me.");
只是另一种方式来做到这一点。
Label lbl = new Label();
new ToolTip().SetToolTip(lbl, "tooltip text here");
我喜欢这个想法;但你的意思是“lbl”而不是“标签”在第二行,对吧? – 2014-11-13 16:31:42
是的,谢谢。好眼睛先生。 – ac0de 2014-11-14 18:59:53
只是分享我的想法......
我创建了一个自定义的类继承Label类。我添加了一个作为Tooltip类和公共属性TooltipText分配的私有变量。然后,给它一个MouseEnter委托方法。这是使用多个Label控件的简单方法,无需担心为每个Label控件分配您的Tooltip控件。
public partial class ucLabel : Label
{
private ToolTip _tt = new ToolTip();
public string TooltipText { get; set; }
public ucLabel() : base() {
_tt.AutoPopDelay = 1500;
_tt.InitialDelay = 400;
// _tt.IsBalloon = true;
_tt.UseAnimation = true;
_tt.UseFading = true;
_tt.Active = true;
this.MouseEnter += new EventHandler(this.ucLabel_MouseEnter);
}
private void ucLabel_MouseEnter(object sender, EventArgs ea)
{
if (!string.IsNullOrEmpty(this.TooltipText))
{
_tt.SetToolTip(this, this.TooltipText);
_tt.Show(this.TooltipText, this.Parent);
}
}
}
在形式或用户控件的InitializeComponent方法(设计器代码),重新分配的标签控制到自定义类:
this.lblMyLabel = new ucLabel();
此外,改变在设计代码的私有变量参考:
private ucLabel lblMyLabel;
但是,每次用户使用Form可视化设计器更改某些内容时,是不是重新生成Designer代码? – ensisNoctis 2017-02-27 11:13:51
- 1. 如何将工具提示添加到Winforms中的Combobox项目
- 2. 如何将工具提示添加到角形标签?
- 3. 将工具提示添加到StripMenuItem C#
- 4. 如何将工具提示添加到vb.net winforms datagrid行?
- 5. 宪章插件提示:添加标签的工具提示
- 6. 如何添加jQuery中追加标签的工具提示
- 7. Jface标签提供程序:如何将工具提示添加到ObservableMapLabelProvider
- 8. 将工具提示添加到动态创建的标签页
- 9. 将工具提示添加到CStatic中
- 10. 将jquery ui工具提示添加到标签
- 11. 如何添加工具提示(或标题标签)到挂毯网格行?
- 12. 如何将工具提示添加到高图中的x轴标签?
- 13. 如何将工具提示功能添加到高图中的X轴标签
- 14. 如何在JSF中为selectItems标签添加工具提示
- 15. 的WinForms工具提示中的WinForms DataGridViewImageColumn
- 16. 将工具提示添加到UIbutton
- 17. 将工具提示添加到组框
- 18. 如何将twitter引导工具提示添加到图标
- 19. 添加没有span标签或标题的工具提示/气泡显示
- 20. 添加工具提示到闪亮的标签
- 21. 如何在HTML CSS标签上添加工具提示
- 22. 如何将工具提示添加到Windows窗体中的“X”?
- 23. 如何将工具提示添加到jtable中的单元格?
- 24. 如何将工具提示添加到TeeChart的Box图中?
- 25. 如何将工具提示添加到表格中的td
- 26. 如何将永久工具提示或标签添加到Charttype系列中指向MSChart c#
- 27. 添加提示标签
- 28. 设置标识并将CSS类添加到Poshy提示工具提示div
- 29. JSlider中标签的工具提示
- 30. 工具提示中的HTML标签
[显示上的文本的鼠标悬停工具提示]的可能的复制(http://stackoverflow.com/questions/873175/displaying-tooltip-on-mouse-hover-of-a-text) – 2016-06-10 19:40:43