public Confirm() { InitializeComponent(); DelProgram = new DelegateText(StudentInfoClass.GetProgram); DelLastName = new DelegateText(StudentInfoClass.GetLastName); DelFirstName = new DelegateText(StudentInfoClass.GetFirstName); DelMiddleName = new DelegateText(StudentInfoClass.GetMiddleName); DelAddress = new DelegateText(StudentInfoClass.GetAddress); DelNumAge = new DelegateNumber(StudentInfoClass.GetAge); DelNumContactNo = new DelegateNumber(StudentInfoClass.GetContactNo); DelStudNo = new DelegateNumber(StudentInfoClass.GetStudentNo); }
static void Main(string[] args) { //用静态方法实例化委托 // DelegateText dtinstance = new DelegateText(new Program().Method2); //定义一个委托对象,初始化为空,即不代表任何方法 DelegateText dtchain = null; //使用“+”符号链接委托,链接多个委托后就成了委托链 dtchain += dtstatic; dtchain += dtinstance; //调用委托链 dtchain(); Console.Read(); }
public void SetInfoText(String strText) { //判断调用者是否位于创建者(UI的)以外的线程 if (InvokeRequired) { //判断垃圾回收线程中是否有基类,判断对象是否被释放 if (Disposing || IsDisposed) { return; } //在拥有控件的基础窗口句柄的线程上,用指定的参数列表执行指定委托。 DelegateText @delegate = new DelegateText(SetInfoText); Invoke(@delegate, strText); } else { InfoText.Text = strText; Refresh(); } }
public IAsyncResult BeginText(int messageOrdinal, AsyncCallback callback) { this._delegateText = this.Text; return this._delegateText.BeginInvoke(messageOrdinal, callback, this._delegateText); }