⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 例7_4复选字体字型
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.RadioButton radioButton3;
		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.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.checkBox2 = new System.Windows.Forms.CheckBox();
            this.checkBox3 = new System.Windows.Forms.CheckBox();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.textBox1.Location = new System.Drawing.Point(40, 31);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(309, 42);
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "字 体 字 型 设 置";
            this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // radioButton1
            // 
            this.radioButton1.Font = new System.Drawing.Font("黑体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.radioButton1.Location = new System.Drawing.Point(43, 123);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new System.Drawing.Size(138, 31);
            this.radioButton1.TabIndex = 1;
            this.radioButton1.Text = "黑体";
            this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
            // 
            // radioButton2
            // 
            this.radioButton2.Font = new System.Drawing.Font("华文新魏", 8.999999F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.radioButton2.Location = new System.Drawing.Point(43, 175);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new System.Drawing.Size(138, 31);
            this.radioButton2.TabIndex = 2;
            this.radioButton2.Text = "华文新魏";
            this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
            // 
            // radioButton3
            // 
            this.radioButton3.Font = new System.Drawing.Font("楷体_GB2312", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.radioButton3.Location = new System.Drawing.Point(43, 237);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.Size = new System.Drawing.Size(138, 30);
            this.radioButton3.TabIndex = 3;
            this.radioButton3.Text = "楷体";
            this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
            // 
            // checkBox1
            // 
            this.checkBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.checkBox1.Location = new System.Drawing.Point(224, 123);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(139, 31);
            this.checkBox1.TabIndex = 4;
            this.checkBox1.Text = "粗体";
            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // checkBox2
            // 
            this.checkBox2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.checkBox2.Location = new System.Drawing.Point(224, 175);
            this.checkBox2.Name = "checkBox2";
            this.checkBox2.Size = new System.Drawing.Size(139, 31);
            this.checkBox2.TabIndex = 5;
            this.checkBox2.Text = "斜体";
            this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
            // 
            // checkBox3
            // 
            this.checkBox3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.checkBox3.Location = new System.Drawing.Point(224, 237);
            this.checkBox3.Name = "checkBox3";
            this.checkBox3.Size = new System.Drawing.Size(139, 30);
            this.checkBox3.TabIndex = 6;
            this.checkBox3.Text = "下划线";
            this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
            this.ClientSize = new System.Drawing.Size(389, 341);
            this.Controls.Add(this.checkBox3);
            this.Controls.Add(this.checkBox2);
            this.Controls.Add(this.checkBox1);
            this.Controls.Add(this.radioButton3);
            this.Controls.Add(this.radioButton2);
            this.Controls.Add(this.radioButton1);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "设置字体字型";
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

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

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

		private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
		{
			if(radioButton3.Checked==true)
				textBox1.Font=new Font("楷体_GB2312",textBox1.Font.Size,
					textBox1.Font.Style);

		}

		private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
		{
			if(checkBox1.Checked==true)
			{
				if(checkBox2.Checked&&checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic|
						FontStyle.Underline);
				else if(checkBox2.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic);
				else if(checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Underline);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Bold);
			}
			else
			{
				if(checkBox2.Checked&&checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Italic|
						FontStyle.Underline);
				else if(checkBox2.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Italic);
				else if(checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Underline);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Regular);
			}
		}

		private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
		{
			if(checkBox2.Checked==true)
			{
				if(checkBox1.Checked&&checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic|
						FontStyle.Underline);
				else if(checkBox1.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic);
				else if(checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Italic|FontStyle.Underline);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Italic);
			}
			else
			{
				if(checkBox1.Checked&&checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Underline);
				else if(checkBox1.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Bold);
				else if(checkBox3.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Underline);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Regular);
			}
		}

		private void checkBox3_CheckedChanged(object sender, System.EventArgs e)
		{
			if(checkBox3.Checked==true)
			{
				if(checkBox1.Checked&&checkBox2.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic|
						FontStyle.Underline);
				else if(checkBox2.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Underline|FontStyle.Italic);
				else if(checkBox1.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Underline);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Underline);
			}
			else
			{
				if(checkBox2.Checked&&checkBox1.Checked)
					textBox1.Font=new Font(textBox1.Font,
						FontStyle.Bold|FontStyle.Italic);
				else if(checkBox2.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Italic);
				else if(checkBox1.Checked)
					textBox1.Font=new Font(textBox1.Font,FontStyle.Bold);
				else 
					textBox1.Font=new Font(textBox1.Font,FontStyle.Regular);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -