C# 字体大小的相关问题

设置字体大小无法这么写,

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();
        }
    }
}
相关推荐
疯狂的喵1 天前
C++编译期多态实现
开发语言·c++·算法
2301_765703141 天前
C++中的协程编程
开发语言·c++·算法
m0_748708051 天前
实时数据压缩库
开发语言·c++·算法
lly2024061 天前
jQuery Mobile 表格
开发语言
惊讶的猫1 天前
探究StringBuilder和StringBuffer的线程安全问题
java·开发语言
m0_748233171 天前
30秒掌握C++核心精髓
开发语言·c++
Fleshy数模1 天前
从数据获取到突破限制:Python爬虫进阶实战全攻略
java·开发语言
Duang007_1 天前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python
froginwe111 天前
Redis 管道技术
开发语言
u0109272711 天前
C++中的RAII技术深入
开发语言·c++·算法