设置字体大小无法这么写,
button1.Font.Size = 20;
这个是只读属性;
把字体大小改为16,
button2.Font = new Font(button2.Font.Name, 16);
程序运行的时候先看一下窗体和控件的默认字体尺寸,都是9;然后点button4把button2的字体调为16,结果如下;
然后点button3,把窗体的字体大小改为16,再输出窗体和控件的字体大小,结果如下;
控件的字体也会同时变为16;如果把窗体的字体调大,窗体尺寸会变大;
cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace fontdemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = this.Font.Size.ToString();
textBox2.Text = button1.Font.Size.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
button2.Font = new Font(button2.Font.Name, 16);
}
private void button3_Click(object sender, EventArgs e)
{
this.Font = new Font(this.Font.Name, 16);
textBox1.Text = this.Font.Size.ToString();
textBox2.Text = button1.Font.Size.ToString();
}
}
}