I had the same question as you, and I went to this site to answer.
Apparently, I did not understand this better, although I was looking through examples in this thread.
I found great use for delegates now that I read: http://www.c-sharpcorner.com/UploadFile/thiagu304/passdata05172006234318PM/passdata.aspx
This might seem more obvious to new users, because Forms is much harder to pass values โโthan ASP.NET websites with POST / GET (QueryString) ..
Basically you define a delegate that takes TextBox text as parameters.
// Form1
// Class Property Definition public delegate void delPassData(TextBox text); // Click Handler private void btnSend_Click(object sender, System.EventArgs e) { Form2 frm= new Form2(); delPassData del=new delPassData(frm.funData); del(this.textBox1); frm.Show(); }
// SUMMARY: defining a delegate, creating a new Form2 class, assigning the funData () function for delegation, passing it to a delegate in a text field. Show form.
// Form2
public void passData(TextBox txtForm1) { label1.Text = txtForm1.Text; }
// SUMMARY: just take TextBox txtForm1 as parameters (as defined in your delete) and assign label text to text text.
Hope this enlightens some use of delegates :) ..
dezza May 10 '10 at 8:42 a.m. 2010-05-10 08:42
source share