I need to make label underline when I enter the label with my mouse. How can I do that? I tried few options but it didn't work. Can anyone tell me how to do that?
Asked
Active
Viewed 2.0k times
10
-
1Have you tried anything? is this winforms, wpf or maybe something else? – DROP TABLE users Dec 31 '13 at 18:46
-
3Metro? WinForms? WPF? Silverlight? Windows Phone? ASP.Net? MonoTouch? – SLaks Dec 31 '13 at 18:46
-
Sorry, didn't mention that. I'm working on WinForms – MarisP Dec 31 '13 at 18:49
3 Answers
19
You can use the MouseEnter
and MouseLeave
events of your label to modify the Font
used
private void OnMouseEnter(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, label1.Font.SizeInPoints, FontStyle.Underline);
}
private void OnMouseLeave(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, label1.Font.SizeInPoints, FontStyle.Regular);
}
If you do not need to modify the font name or size you can directly use new Font(label1.Font, FontStyle.Underline)
Also, if you need to add multiple styles, you can use the |
operator :
label1.Font = new Font(label1.Font.Name, label1.Font.SizeInPoints, FontStyle.Underline | FontStyle.Bold);

Pierre-Luc Pineault
- 8,993
- 6
- 40
- 55
2
You can use the MouseEnter
and MouseLeave
events like so:
private void label1_MouseEnter(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font, FontStyle.Underline);
}
private void label1_MouseLeave(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font, FontStyle.Regular);
}

CAbbott
- 8,078
- 4
- 31
- 38
2
Use this.
set a new Instance of Font
private void label1_MouseHover(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, 8, FontStyle.Underline);
label1.Font = new Font(label1.Font.Name, 8, FontStyle.Bold|FontStyle.Underline);//For Bold Also
}
private void label1_MouseLeave(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, 8);
}

Amit Bisht
- 4,870
- 14
- 54
- 83