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()方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.