c# winform 响应Windows窗体应用程序中的字体方案更改
程序员文章站
2024-01-04 21:45:16
...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WinFormsAutoScaling
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Font = SystemFonts.IconTitleFont;
SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.Window)
{
this.Font = SystemFonts.IconTitleFont;
}
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
}
}
}
桌面修改字体大小,界面随之变化