C# 字体大小的相关问题

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

    button1.Font.Size = 20;

这个是只读属性;

把字体大小改为16,

    button2.Font = new Font(button2.Font.Name, 16);

程序运行的时候先看一下窗体和控件的默认字体尺寸,都是9;然后点button4把button2的字体调为16,结果如下;

然后点button3,把窗体的字体大小改为16,再输出窗体和控件的字体大小,结果如下;

 

控件的字体也会同时变为16;如果把窗体的字体调大,窗体尺寸会变大;

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语言大小字母转换程序

    2024-02-11 22:40:02       48 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-11 22:40:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-11 22:40:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-11 22:40:02       82 阅读
  4. Python语言-面向对象

    2024-02-11 22:40:02       91 阅读

热门阅读

  1. 深度学习模型与神经网络可视化工具

    2024-02-11 22:40:02       51 阅读
  2. STM32 适合人群

    2024-02-11 22:40:02       50 阅读
  3. 12.3 OpenGL顶点后处理:平面着色

    2024-02-11 22:40:02       50 阅读
  4. C++ dfs的状态表示(五十二)【第十二篇】

    2024-02-11 22:40:02       53 阅读
  5. MSc CDA Take-Home

    2024-02-11 22:40:02       60 阅读
  6. golang 集成sentry:http.Client

    2024-02-11 22:40:02       50 阅读
  7. 20190726 ApacheHttpClient-自签证书与系统证书共存

    2024-02-11 22:40:02       49 阅读
  8. MySQL-管理

    2024-02-11 22:40:02       50 阅读
  9. 【力扣每日一题】力扣1696跳跃游戏VI

    2024-02-11 22:40:02       63 阅读
  10. Linux 服务管理两种方式service和systemctl

    2024-02-11 22:40:02       39 阅读