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();
        }
    }
}
相关推荐
Scout-leaf5 小时前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户298698530148 小时前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools1 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的2 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21882 天前
.NET 本地Db数据库-技术方案选型
windows·c#
郑州光合科技余经理2 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
lindexi2 天前
dotnet DirectX 通过可等待交换链降低输入渲染延迟
c#·directx·d2d·direct2d·vortice
feifeigo1232 天前
matlab画图工具
开发语言·matlab
dustcell.2 天前
haproxy七层代理
java·开发语言·前端
norlan_jame2 天前
C-PHY与D-PHY差异
c语言·开发语言