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

📄 form1.cs

📁 《c#技术内幕代码》
💻 CS
字号:
namespace ch9_5
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.Windows.Forms.CheckBox checkBox3;
		private System.Windows.Forms.CheckBox checkBox2;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.RichTextBox richTextBox1;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container ();
			this.textBox1 = new System.Windows.Forms.TextBox ();
			this.label1 = new System.Windows.Forms.Label ();
			this.richTextBox1 = new System.Windows.Forms.RichTextBox ();
			this.checkBox3 = new System.Windows.Forms.CheckBox ();
			this.checkBox1 = new System.Windows.Forms.CheckBox ();
			this.button1 = new System.Windows.Forms.Button ();
			this.checkBox2 = new System.Windows.Forms.CheckBox ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			textBox1.Location = new System.Drawing.Point (88, 232);
			textBox1.TabIndex = 2;
			textBox1.Size = new System.Drawing.Size (176, 20);
			label1.Location = new System.Drawing.Point (8, 232);
			label1.Text = "Enter the text:";
			label1.Size = new System.Drawing.Size (100, 23);
			label1.TabIndex = 1;
			richTextBox1.Size = new System.Drawing.Size (312, 208);
			richTextBox1.TabIndex = 0;
			richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
			richTextBox1.Location = new System.Drawing.Point (8, 8);
			checkBox3.Location = new System.Drawing.Point (112, 256);
			checkBox3.Text = "Underline";
			checkBox3.Size = new System.Drawing.Size (72, 24);
			checkBox3.TabIndex = 6;
			checkBox1.Location = new System.Drawing.Point (8, 256);
			checkBox1.Text = "Bold";
			checkBox1.Size = new System.Drawing.Size (48, 24);
			checkBox1.TabIndex = 4;
			button1.Location = new System.Drawing.Point (272, 232);
			button1.Size = new System.Drawing.Size (48, 23);
			button1.TabIndex = 3;
			button1.Text = "&Add";
			button1.Click += new System.EventHandler (this.button1_Click);
			checkBox2.Location = new System.Drawing.Point (64, 256);
			checkBox2.Text = "Italic";
			checkBox2.Size = new System.Drawing.Size (48, 24);
			checkBox2.TabIndex = 5;
			this.Text = "Rich Text Demo";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.ClientSize = new System.Drawing.Size (328, 325);
			this.Controls.Add (this.checkBox3);
			this.Controls.Add (this.checkBox2);
			this.Controls.Add (this.checkBox1);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.textBox1);
			this.Controls.Add (this.label1);
			this.Controls.Add (this.richTextBox1);
		}
		protected void AddText( string text )
		{
			FontStyle fs = new FontStyle();
			if ( this.checkBox1.Checked)
			{
				fs |= FontStyle.Bold;
			}
			if ( this.checkBox2.Checked)
			{
				fs |= FontStyle.Italic;
			}
			if ( this.checkBox3.Checked )
			{
				fs |= FontStyle.Underline;
			}

			Font f = new Font("Arial", 12, fs);
			int start = this.richTextBox1.Text.Length;
			this.richTextBox1.Text += text;
			this.richTextBox1.SelectionStart = 
				start;
			this.richTextBox1.SelectionLength = 
				text.Length;
			this.richTextBox1.SelectionFont = f;

		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
            if ( this.textBox1.Text.Length != 0 )
			{
				AddText( this.textBox1.Text );
				this.textBox1.Text = "";
			}
		}

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) 
        {
            Application.Run(new Form1());
        }
    }
}

⌨️ 快捷键说明

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