-2
  • 1

I have this small code that when mouse over on a label it should change the font size etc....

        private void label1_MouseHover(object sender, EventArgs e)
    {
        label1.Font = new Font("arial",18, FontStyle.Bold,GraphicsUnit.Pixel);
    }

so it's work , but i want to return the default value to this label when i move the mouse again

  • 2

how to make the button have default key that when i press it the button will do it's work ?

do any one have course about events ?

Lubbock
  • 63
  • 2
  • 13
  • Set the default properties back to your label in the `MouseLeave` event. – Salah Akbari Dec 21 '17 at 12:07
  • 1
    Please ask one question at a time. Questions asking for tutorials or courses are off-topic. – Thomas Weller Dec 21 '17 at 12:07
  • What's mean that default value? Do you want label Text when clicked? – Metehan Senol Dec 21 '17 at 12:08
  • Possible duplicate of [Best way to implement keyboard shortcuts in a Windows Forms application?](https://stackoverflow.com/questions/400113/best-way-to-implement-keyboard-shortcuts-in-a-windows-forms-application) – Sinatr Dec 21 '17 at 12:08
  • @MetehanSenol like i have the default font size of this lab is 18 and when mouse over it's change to 20 but when i move the mouse again i need to return it to the default value ( 18 ) – Lubbock Dec 21 '17 at 12:12

2 Answers2

0

You should use MouseEnter and MouseLeave event.

In MouseEnter set your "hover"-font. In MouseLeave reset to default font.

Label label = new Label();
label.Text = "Hello World!";
label.MouseEnter += label_MouseEnter;
label.MouseLeave += label_MouseLeave;

Example changes from Segoe UI 12 to 18 pixel

private void label_MouseEnter(object sender, EventArgs e)
{
    Label label = sender as Label;

    if(label != null)
    {
        label.Font = new Font("Segoe UI", 12, FontStyle.Bold, GraphicsUnit.Pixel);
    }
}
private void label_MouseLeave(object sender, EventArgs e)
{
    Label label = sender as Label;

    if (label != null)
    {
        label.Font = new Font("Segoe UI", 18, FontStyle.Bold, GraphicsUnit.Pixel);
    }
}
0
dropoutcoder
  • 2,627
  • 2
  • 14
  • 32