该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//添加字体列表项
cmbFontName.Items.Add("宋体");
cmbFontName.Items.Add("隶书");
cmbFontName.Items.Add("楷体_GB2312");
cmbFontName.Items.Add("黑体");
cmbFontName.Items.Add("幼圆");
cmbFontName.SelectedIndex = 0; //设置当前项
//添加字型列表项
cmbFontStyle.Items.Add("常规");
cmbFontStyle.Items.Add("粗体");
cmbFontStyle.Items.Add("斜体");
cmbFontStyle.Items.Add("粗斜体");
cmbFontStyle.SelectedIndex = 0; //设置当前项
//通过循环添加字体大小列表项
for (int i = 6; i < 72; i += 2)
cmbFontSize.Items.Add(i);
cmbFontSize.SelectedIndex = 3; //设置当前项
txtView.Text = "字体演示";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtView.Font = new Font(cmbFontName.Text, txtView.Font.Size,
txtView.Font.Style);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cmbFontStyle.SelectedIndex) //通过switch语句选择字形
{
case 0: //设置为常规字体
txtView.Font = new Font(txtView.Font, FontStyle.Regular);
break;
case 1: //设置为粗体
txtView.Font = new Font(txtView.Font, FontStyle.Bold);
break;
case 2: //设置为斜体
txtView.Font = new Font(txtView.Font, FontStyle.Italic);
break;
case 3: //设置为粗斜体
txtView.Font = new Font(txtView.Font, FontStyle.Italic | FontStyle.Bold);
break;
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
int n;
n = Convert.ToInt16(cmbFontSize.Text);
//设置字体
txtView.Font = new Font(txtView.Font.FontFamily, n, txtView.Font.Style);
}
}
}