📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Exam4_7_1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.RadioButton radioButton6;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.radioButton6 = new System.Windows.Forms.RadioButton();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox1.Location = new System.Drawing.Point(8, 8);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(320, 48);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "欢迎进入Visual C#";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButton3);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Location = new System.Drawing.Point(11, 64);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(104, 104);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "字体";
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(16, 72);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(72, 24);
this.radioButton3.TabIndex = 2;
this.radioButton3.Text = "楷体";
this.radioButton3.Click += new System.EventHandler(this.radioButton3_Click);
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(16, 48);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(72, 16);
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "隶书";
this.radioButton2.Click += new System.EventHandler(this.radioButton2_Click);
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(16, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(72, 24);
this.radioButton1.TabIndex = 0;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "宋体";
this.radioButton1.Click += new System.EventHandler(this.radioButton1_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.radioButton6);
this.groupBox2.Controls.Add(this.radioButton5);
this.groupBox2.Controls.Add(this.radioButton4);
this.groupBox2.Location = new System.Drawing.Point(123, 64);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(96, 104);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "字号";
//
// radioButton6
//
this.radioButton6.Location = new System.Drawing.Point(24, 72);
this.radioButton6.Name = "radioButton6";
this.radioButton6.Size = new System.Drawing.Size(56, 24);
this.radioButton6.TabIndex = 2;
this.radioButton6.Text = "一号";
this.radioButton6.Click += new System.EventHandler(this.radioButton6_Click);
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(24, 43);
this.radioButton5.Name = "radioButton5";
this.radioButton5.Size = new System.Drawing.Size(56, 24);
this.radioButton5.TabIndex = 1;
this.radioButton5.Text = "三号";
this.radioButton5.Click += new System.EventHandler(this.radioButton5_Click);
//
// radioButton4
//
this.radioButton4.Checked = true;
this.radioButton4.Location = new System.Drawing.Point(24, 16);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(48, 24);
this.radioButton4.TabIndex = 0;
this.radioButton4.TabStop = true;
this.radioButton4.Text = "小五";
this.radioButton4.Click += new System.EventHandler(this.radioButton4_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.checkBox3);
this.groupBox3.Controls.Add(this.checkBox2);
this.groupBox3.Controls.Add(this.checkBox1);
this.groupBox3.Location = new System.Drawing.Point(227, 64);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(95, 104);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "字型";
//
// checkBox3
//
this.checkBox3.Location = new System.Drawing.Point(20, 71);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(68, 24);
this.checkBox3.TabIndex = 2;
this.checkBox3.Text = "下划线";
this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
//
// checkBox2
//
this.checkBox2.Location = new System.Drawing.Point(21, 41);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(67, 24);
this.checkBox2.TabIndex = 1;
this.checkBox2.Text = "斜体";
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(21, 13);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(64, 27);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "粗";
this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click);
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(344, 181);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "单选钮和复选钮的使用";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void radioButton1_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font("宋体",textBox1.Font.Size,textBox1.Font.Style);
}
private void radioButton2_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font("隶书",textBox1.Font.Size,textBox1.Font.Style);
}
private void radioButton3_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font("楷体",textBox1.Font.Size,textBox1.Font.Style);
}
private void radioButton4_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font(textBox1.Font.FontFamily,9,textBox1.Font.Style);
}
private void radioButton5_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font(textBox1.Font.FontFamily,15.75f,textBox1.Font.Style);
}
private void radioButton6_Click(object sender, System.EventArgs e)
{
textBox1.Font=new Font(textBox1.Font.FontFamily,26.25f,textBox1.Font.Style);
}
private void checkBox1_Click(object sender, System.EventArgs e)
{
}
private void changeTextStyle()
{
FontStyle fStyle=textBox1.Font.Style;
if(checkBox1.Checked==true&&checkBox3.Checked==true&&checkBox3.Checked==true)
fStyle=(FontStyle)(FontStyle.Bold|FontStyle.Italic|FontStyle.Underline);
else if(checkBox1.Checked==true&&checkBox2.Checked)
fStyle=(FontStyle)(FontStyle.Bold|FontStyle.Italic);
else if(checkBox1.Checked==true&&checkBox3.Checked)
fStyle=(FontStyle)(FontStyle.Bold|FontStyle.Underline);
else if(checkBox2.Checked==true&&checkBox3.Checked)
fStyle=(FontStyle)(FontStyle.Italic|FontStyle.Underline);
else if(checkBox1.Checked==true)
fStyle=(FontStyle)(FontStyle.Bold);
else if(checkBox2.Checked==true)
fStyle=(FontStyle)(FontStyle.Italic);
else if(checkBox3.Checked==true)
fStyle=(FontStyle)(FontStyle.Underline);
else
fStyle=FontStyle.Regular;
textBox1.Font=new Font(textBox1.Font.FontFamily,textBox1.Font.Size,fStyle);
}
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
changeTextStyle();
}
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
changeTextStyle();
}
private void checkBox3_CheckedChanged(object sender, System.EventArgs e)
{
changeTextStyle();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -