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

📄 customcontrol.cs

📁 很好的学习资料,对菜鸟学习c#很有帮助啊,希望你们好好学习
💻 CS
字号:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections.Specialized;

namespace Custom
{
	/// <summary>
	/// WebCustomControl1 的摘要说明。
	/// </summary>
	[DefaultProperty("Text"),
		ToolboxData("<{0}:Rendered runat=server></{0}:Rendered>")]
	public class Rendered : Control, IPostBackDataHandler, IPostBackEventHandler
	{
   
		private String text1;
		private String text2;
		private String text = "点击提交按钮看是否匹配.";
		private int number = 100;
      

		private int Sum
		{
			get 
			{         
				return Int32.Parse(text1) + 
					Int32.Parse(text2);
			}   
		}
      
		public int Number
		{
			get
			{
				return number;
			}
			set
			{
				number = value;
			}
		}
      
      
		public String Text 
		{
			get 
			{
				return text;
			}
			set 
			{   
				text = value;
			}         
		}
      
		public event CheckEventHandler Check;
      
		protected virtual void OnCheck(CheckEventArgs ce)
		{
			if (Check != null)
			{
				Check(this,ce);
			}
		}
      
		public virtual bool LoadPostData(string postDataKey, 
			NameValueCollection values) 
		{
			text1 = values[UniqueID + "t1"];
			text2 = values[UniqueID+ "t2"];
			Page.RegisterRequiresRaiseEvent(this);
			return false;
		}
      
		public virtual void RaisePostDataChangedEvent() 
		{
		}
      
		public void RaisePostBackEvent(string eventArgument)
		{
         
			OnCheck(new CheckEventArgs(Sum - Number));
		}
      
      
		protected override void Render(HtmlTextWriter output) 
		{
			output.Write ("<h3>第一个数字 : ");
			output.Write("<INPUT type= text name = " + this.UniqueID + "t1" + 
				" value = '0' >");
			output.Write("</h3><br>");   
			output.Write ("<br><h3>第二个数字: ");
			output.Write("<INPUT type= text name = " + this.UniqueID + "t2" + 
				" value =  '0' >");
			output.Write("</h3><br>");   
			output.Write("<br><br><input type= submit name = " + 
				this.UniqueID + " value= '提交'>");
			output.Write("<br><br><span style='height:50px;width:500px;'>"
				+ Text + "</span>");
		}
	}  
	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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -