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

📄 form1.cs

📁 c#程序部分代码我没有用过是我的老师给我的用于arcGIS engine 开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace cs_AddRemoveHandler
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtN1;
		private System.Windows.Forms.TextBox txtN2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label lblAns;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnDel;
		/// <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 Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.txtN1 = new System.Windows.Forms.TextBox();
			this.txtN2 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.lblAns = new System.Windows.Forms.Label();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnDel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// txtN1
			// 
			this.txtN1.Location = new System.Drawing.Point(40, 40);
			this.txtN1.Name = "txtN1";
			this.txtN1.Size = new System.Drawing.Size(72, 21);
			this.txtN1.TabIndex = 0;
			this.txtN1.Text = "";
			this.txtN1.TextChanged += new System.EventHandler(this.MyButtonClick);
			// 
			// txtN2
			// 
			this.txtN2.Location = new System.Drawing.Point(152, 40);
			this.txtN2.Name = "txtN2";
			this.txtN2.Size = new System.Drawing.Size(72, 21);
			this.txtN2.TabIndex = 1;
			this.txtN2.Text = "";
			this.txtN2.TextChanged += new System.EventHandler(this.MyButtonClick);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 18F);
			this.label1.Location = new System.Drawing.Point(120, 40);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(24, 23);
			this.label1.TabIndex = 2;
			this.label1.Text = "+";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("宋体", 18F);
			this.label2.Location = new System.Drawing.Point(224, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(24, 23);
			this.label2.TabIndex = 3;
			this.label2.Text = "=";
			// 
			// lblAns
			// 
			this.lblAns.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(192)));
			this.lblAns.Font = new System.Drawing.Font("宋体", 12F);
			this.lblAns.Location = new System.Drawing.Point(264, 40);
			this.lblAns.Name = "lblAns";
			this.lblAns.Size = new System.Drawing.Size(104, 24);
			this.lblAns.TabIndex = 4;
			// 
			// btnAdd
			// 
			this.btnAdd.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnAdd.Location = new System.Drawing.Point(40, 80);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.TabIndex = 5;
			this.btnAdd.Text = "新增事件";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnDel
			// 
			this.btnDel.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnDel.Location = new System.Drawing.Point(152, 80);
			this.btnDel.Name = "btnDel";
			this.btnDel.TabIndex = 6;
			this.btnDel.Text = "删除事件";
			this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(408, 198);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnDel,
																		  this.btnAdd,
																		  this.lblAns,
																		  this.label2,
																		  this.label1,
																		  this.txtN2,
																		  this.txtN1});
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		private void MyButtonClick(object sender, System.EventArgs e)
		{
			try
			{
				lblAns.Text = 
					(float.Parse(txtN1.Text) + float.Parse(txtN2.Text)).ToString();
			}
			catch
			{
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			txtN1.TextChanged += new EventHandler(MyButtonClick);
			txtN2.TextChanged += new EventHandler(MyButtonClick);

		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			txtN1.TextChanged += new EventHandler(MyButtonClick);
			txtN2.TextChanged += new EventHandler(MyButtonClick);

		}

		private void btnDel_Click(object sender, System.EventArgs e)
		{
			txtN1.TextChanged -= new EventHandler(MyButtonClick);
			txtN2.TextChanged -= new EventHandler(MyButtonClick);

		}
	}
}

⌨️ 快捷键说明

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