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

📄 form1.cs

📁 c#设计模式随书源码 c#设计模式随书源码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Delegate
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txName;
		private System.Windows.Forms.Button btProcess;
		private System.Windows.Forms.ListBox lsBox;
		private System.Windows.Forms.RadioButton opCap;
		private System.Windows.Forms.RadioButton opLower;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private delegate string fTxDelegate(string s);	//declare delegate
		fTxDelegate ftx;  //instance of delegate
		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			btProcess.Enabled =false;
			
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.txName = new System.Windows.Forms.TextBox();
			this.btProcess = new System.Windows.Forms.Button();
			this.lsBox = new System.Windows.Forms.ListBox();
			this.opCap = new System.Windows.Forms.RadioButton();
			this.opLower = new System.Windows.Forms.RadioButton();
			this.SuspendLayout();
			// 
			// txName
			// 
			this.txName.Location = new System.Drawing.Point(56, 24);
			this.txName.Name = "txName";
			this.txName.Size = new System.Drawing.Size(160, 20);
			this.txName.TabIndex = 0;
			this.txName.Text = "";
			// 
			// btProcess
			// 
			this.btProcess.Location = new System.Drawing.Point(96, 72);
			this.btProcess.Name = "btProcess";
			this.btProcess.Size = new System.Drawing.Size(64, 24);
			this.btProcess.TabIndex = 1;
			this.btProcess.Text = "Process";
			this.btProcess.Click += new System.EventHandler(this.btProcess_Click);
			// 
			// lsBox
			// 
			this.lsBox.Location = new System.Drawing.Point(56, 144);
			this.lsBox.Name = "lsBox";
			this.lsBox.Size = new System.Drawing.Size(160, 82);
			this.lsBox.TabIndex = 2;
			// 
			// opCap
			// 
			this.opCap.Location = new System.Drawing.Point(192, 72);
			this.opCap.Name = "opCap";
			this.opCap.Size = new System.Drawing.Size(80, 16);
			this.opCap.TabIndex = 3;
			this.opCap.Text = "Capital";
			this.opCap.CheckedChanged += new System.EventHandler(this.opCap_CheckedChanged);
			// 
			// opLower
			// 
			this.opLower.Location = new System.Drawing.Point(192, 104);
			this.opLower.Name = "opLower";
			this.opLower.Size = new System.Drawing.Size(72, 16);
			this.opLower.TabIndex = 4;
			this.opLower.Text = "Lower";
			this.opLower.CheckedChanged += new System.EventHandler(this.opLower_CheckedChanged);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.opLower,
																		  this.opCap,
																		  this.lsBox,
																		  this.btProcess,
																		  this.txName});
			this.Name = "Form1";
			this.Text = "Delegate Demo";
			this.ResumeLayout(false);

		}
		#endregion

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

		private void opCap_CheckedChanged(object sender, System.EventArgs e) {
			btProcess.Enabled =true;
			//assign an instance method to the delegate
			//create an instance of the Capital class
			ftx = new fTxDelegate (new Capital().fixText);
		}
		//-----
		private void opLower_CheckedChanged(object sender, System.EventArgs e) {
			btProcess.Enabled =true;
			//assign a static method to the delegate
			//the Lower class has a static method fixText
			ftx = new fTxDelegate (Lower.fixText);
		}

		private void btProcess_Click(object sender, System.EventArgs e) {
			lsBox.Items.Add ( ftx(txName.Text ));
		}
	}
}

⌨️ 快捷键说明

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