How to add a tooltip or tooltip to a label in C # Winforms?

Label seems to have no Hint or ToolTip or Hovertext . So, what is the preferred method for displaying a tooltip, tooltip, or hover text when approaching a Label with the mouse?

+69
c # winforms tooltip label
Mar 19 '12 at 18:52
source share
5 answers

First you must add the ToolTip element to your form. Then you can set the text that it should display for other controls.

Here is a screenshot showing the designer after adding a ToolTip control called toolTip1 :

enter image description here

+89
Mar 19 '12 at 18:54
source share
 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."); 
+67
Mar 19 '12 at 18:55
source share
 System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip(); ToolTip1.SetToolTip( Label1, "Label for Label1"); 
+17
Mar 19 '12 at 18:55
source share

just another way to do it.

 Label lbl = new Label(); new ToolTip().SetToolTip(lbl, "tooltip text here"); 
+11
Nov 13 '14 at 12:35
source share

Just to share your idea ...

I created my own class to inherit the Label class. I added a private variable assigned as the Tooltip class and the public property of TooltipText. Then he gave it the MouseEnter delegate method. This is an easy way to work with multiple Label controls, and you don’t have to worry about assigning a Tooltip control to each Label control.

  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); } } } 

In a form or custom InitializeComponent method (constructor code), reassign the Label control to a user class:

 this.lblMyLabel = new ucLabel(); 

Also change the link to the private variable in the constructor code:

 private ucLabel lblMyLabel; 
+4
Mar 09 '16 at 1:10
source share



All Articles