C# 更改字体和字型

来源:百度知道 编辑:UC知道 时间:2024/05/14 11:38:46
我只把前面的三种字体写出来了 后面的就不知道怎么办了 如果要把每种情况列出来也太多了 请大侠帮忙!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 字体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
textBox1.Font = new Font("华文新魏", textBox1.Font.Size,textBox1.Font.Style);
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
textBox1.Font = new Font("黑体", textBox1.Font.Size,textBox1.Font.Style);
}

非要说的话很麻烦

你设计的时候就不合理

你干脆用一个DropDownList 。 它里面的每个Item 的value 等于 楷体 黑体之类的
然后cs里根据 DropDownList 的SelectedValue 值,再给textBox1.Font赋值

写一个方法
private void SetFont(string FontKind)
{
textBox1.Font = new Font(FontKind,textBox1.Font.Size,textBox1.Font.Style);
}
这样可以简化,至于界面上,你可以做成下拉菜单,而不是radioButton3

你编程的工具软件其实早就有系统代码,你只要引用出来就行了,不用这样麻烦的写那么多的

用控件!