form1.cs

来自「《c#技术内幕代码》」· CS 代码 · 共 192 行

CS
192
字号
namespace Ch7_13
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.Button button2;
		private System.WinForms.Button button1;
		private System.WinForms.RadioButton questionMark;
		private System.WinForms.RadioButton stopSign;
		private System.WinForms.RadioButton exclamationPoint;
		private System.WinForms.GroupBox groupBox2;
		private System.WinForms.TextBox textBox1;
		private System.WinForms.RadioButton yesnobuttons;
		private System.WinForms.RadioButton okcancelbutton;
		private System.WinForms.RadioButton okbutton;
		private System.WinForms.GroupBox groupBox1;
		private System.WinForms.Label label1;

        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.groupBox1 = new System.WinForms.GroupBox ();
			this.questionMark = new System.WinForms.RadioButton ();
			this.textBox1 = new System.WinForms.TextBox ();
			this.button2 = new System.WinForms.Button ();
			this.groupBox2 = new System.WinForms.GroupBox ();
			this.okcancelbutton = new System.WinForms.RadioButton ();
			this.okbutton = new System.WinForms.RadioButton ();
			this.exclamationPoint = new System.WinForms.RadioButton ();
			this.stopSign = new System.WinForms.RadioButton ();
			this.label1 = new System.WinForms.Label ();
			this.yesnobuttons = new System.WinForms.RadioButton ();
			this.button1 = new System.WinForms.Button ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			groupBox1.Location = new System.Drawing.Point (24, 72);
			groupBox1.TabIndex = 1;
			groupBox1.TabStop = false;
			groupBox1.Text = "Buttons";
			groupBox1.Size = new System.Drawing.Size (432, 112);
			questionMark.Location = new System.Drawing.Point (24, 96);
			questionMark.Text = "Question Mark";
			questionMark.Size = new System.Drawing.Size (152, 23);
			questionMark.TabIndex = 2;
			textBox1.Location = new System.Drawing.Point (120, 32);
			textBox1.TabIndex = 2;
			textBox1.Size = new System.Drawing.Size (208, 20);
			button2.Location = new System.Drawing.Point (280, 344);
			button2.Size = new System.Drawing.Size (75, 23);
			button2.TabIndex = 5;
			button2.Text = "&Show It";
			button2.Click += new System.EventHandler (this.button2_Click);
			groupBox2.Location = new System.Drawing.Point (24, 200);
			groupBox2.TabIndex = 3;
			groupBox2.TabStop = false;
			groupBox2.Text = "Icons";
			groupBox2.Size = new System.Drawing.Size (432, 128);
			okcancelbutton.Location = new System.Drawing.Point (16, 48);
			okcancelbutton.Text = "ok and cancel";
			okcancelbutton.Size = new System.Drawing.Size (100, 23);
			okcancelbutton.TabIndex = 1;
			okbutton.Location = new System.Drawing.Point (16, 24);
			okbutton.Text = "Ok";
			okbutton.Size = new System.Drawing.Size (184, 16);
			okbutton.TabIndex = 0;
			exclamationPoint.Location = new System.Drawing.Point (24, 24);
			exclamationPoint.Text = "Exclamation Point";
			exclamationPoint.Size = new System.Drawing.Size (144, 23);
			exclamationPoint.TabIndex = 0;
			stopSign.Location = new System.Drawing.Point (24, 64);
			stopSign.Text = "Stop Sign";
			stopSign.Size = new System.Drawing.Size (152, 23);
			stopSign.TabIndex = 1;
			label1.Location = new System.Drawing.Point (24, 32);
			label1.Text = "Text to Display:";
			label1.Size = new System.Drawing.Size (112, 16);
			label1.TabIndex = 0;
			yesnobuttons.Location = new System.Drawing.Point (16, 80);
			yesnobuttons.Text = "yes and no buttons";
			yesnobuttons.Size = new System.Drawing.Size (120, 23);
			yesnobuttons.TabIndex = 2;
			button1.Location = new System.Drawing.Point (32, 344);
			button1.Size = new System.Drawing.Size (75, 23);
			button1.TabIndex = 4;
			button1.Text = "&Close";
			button1.Click += new System.EventHandler (this.button1_Click);
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.ClientSize = new System.Drawing.Size (496, 373);
			groupBox1.Controls.Add (this.yesnobuttons);
			groupBox1.Controls.Add (this.okcancelbutton);
			groupBox1.Controls.Add (this.okbutton);
			this.Controls.Add (this.button2);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.groupBox2);
			this.Controls.Add (this.textBox1);
			this.Controls.Add (this.groupBox1);
			this.Controls.Add (this.label1);
			groupBox2.Controls.Add (this.questionMark);
			groupBox2.Controls.Add (this.stopSign);
			groupBox2.Controls.Add (this.exclamationPoint);
		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
           Close();
		}

		protected void button2_Click (object sender, System.EventArgs e)
		{
			int nOptions = 0;
			if ( this.questionMark.Checked )
			{
				nOptions = MessageBox.IconQuestion;
			}
			if ( this.stopSign.Checked )
			{
				nOptions = MessageBox.IconHand;
			}
			if ( this.exclamationPoint.Checked )
			{
				nOptions = MessageBox.IconExclamation;
			}
			int nButtons = 0;
			// Now, check the button options
			if ( this.yesnobuttons.Checked )
			{
               nButtons = MessageBox.YesNo;
			}
			if ( this.okcancelbutton.Checked )
			{
				nButtons = MessageBox.OKCancel;
			}
			if ( this.okbutton.Checked )
			{
				nButtons = MessageBox.OK;
			}
			MessageBox.Show( this, this.textBox1.Text,
				"MessageBox",
				nOptions | nButtons );

		}

        /// <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 + =
减小字号Ctrl + -
显示快捷键?