myusercontrol.ascx.cs

来自「很好的学习资料,对菜鸟学习c#很有帮助啊,希望你们好好学习」· CS 代码 · 共 113 行

CS
113
字号
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CompositeControl
{
	

	/// <summary>
	///		MyUserControl 的摘要说明。
	/// </summary>
	public abstract class MyUserControl : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.TextBox box1;
		protected System.Web.UI.WebControls.TextBox box2;
		protected System.Web.UI.WebControls.Button button;
		protected System.Web.UI.WebControls.Label label;

		private int Sum
		{
			get 
			{
				EnsureChildControls();
				return Int32.Parse(box1.Text) + 
					Int32.Parse(box2.Text);
			}                 
		}
      
		public int Number = 100;
      
      
		public string Text
		{
			get
			{
				EnsureChildControls();
				return label.Text;
			}
			set
			{
				EnsureChildControls();
				label.Text = value;
			}
		}
      
      
		public event CheckEventHandler Check;
      
		public virtual void OnCheck(CheckEventArgs e)
		{
			if (Check != null)
			{
				Check(this,e);
			}
		}
      
      
		public void Button_Clicked(Object sender, EventArgs e)
		{
			OnCheck(new CheckEventArgs(Sum - Number));
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		设计器支持所需的方法 - 不要使用
		///		代码编辑器修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
	public class CheckEventArgs : EventArgs
	{
		private bool match = false;
            
		public CheckEventArgs (int difference)
		{
			if (difference == 0)
			{
				match = true;
			}
		}
		public bool Match
		{
			get
			{
				return match;
			}
		}
	}
      
	public delegate void CheckEventHandler(object sender, CheckEventArgs ce);

}

⌨️ 快捷键说明

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