简体   繁体   English

标签上的鼠标悬停字体大小更改

[英]Mouse hover font size change on label

Novice here, wanted to try to resize text in a label with a simple mouse over, but everything I seem to be trying isn't exactly working. 这里的新手想用一个简单的鼠标悬停来调整标签中文本的大小,但是我似乎尝试的所有方法都无法正常工作。 Am I forgetting a property in the label? 我会忘记标签中的属性吗? or is it the code? 还是代码?

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void OnMouseEnter(object sender, EventArgs e)
    {
        label1.Font = new Font(label1.Font.Name, 20, FontStyle.Regular);
    }

    private void OnMouseLeave(object sender, EventArgs e)
    {
        label1.Font = new Font(label1.Font.Name, 9, FontStyle.Regular);
    }

    private void label1_Click(object sender, EventArgs e)
    {
    }
}

You just forgot to attach your events didn't you: 您只是忘了附加活动,不是吗:

public Form1()
{
     InitializeComponent();

     label1.MouseEnter += OnMouseEnter;
     label1.MouseLeave += OnMouseLeave;
}

Or you can just do that through the designer. 或者,您也可以通过设计师来完成。

更改ui属性时,请确保调用该控件的Refresh()或Invalidate()方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM