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();
        }
    }
}
相关推荐
qq_334903157 分钟前
高性能网络协议栈
开发语言·c++·算法
阿贵---11 分钟前
模板编译期循环展开
开发语言·c++·算法
2601_9540236611 分钟前
Beyond the Hype: Deconstructing the 2025 High-Performance Stack for Agencies
java·开发语言·算法·seo·wordpress·gpl
l1t15 分钟前
DeepSeek 辅助编写python程序求解欧拉计划932题:2025数
开发语言·python·欧拉计划
2401_8331977318 分钟前
嵌入式C++电源管理
开发语言·c++·算法
ms_27_data_develop21 分钟前
Java——集合
java·开发语言
灰色小旋风22 分钟前
力扣22 括号生成(C++)
开发语言·数据结构·c++·算法·leetcode
2501_9249526924 分钟前
模板编译期哈希计算
开发语言·c++·算法
xiaoye-duck26 分钟前
C++ STL map 系列深度解析:从底层原理、核心接口到实战场景
开发语言·c++·stl
2201_7586426430 分钟前
嵌入式C++开发注意事项
开发语言·c++·算法