C # event parameter [delegate]

Source: Internet
Author: User
Since C # has an event in Event Callback, why not? In addition, events play a more convenient role in form communication. We know that events are actually state capturing, at the end, I will give an example of the capture status. First, let's look at the examples of data operations. Form2:
// Define a delegate that requires a string-type parameter
Publicdelegate void MyDelegate (string text );
Public partial class Form2: Form1
{
// Define the delegate event
Public event MyDelegate MyEvent;
Public Form2 (string text)
{
InitializeComponent ();
This. textBox1.Text = text;
}
Private void btnChange_Click (object sender, EventArgs e)
{
// Trigger the event and send the modified text back
MyEvent (this. textBox1.Text );
This. Close ();
}
}

Form1: public partial class Form1: Form
{
Public int index = 0;
Public string text = null;
Public Form1 ()
{
InitializeComponent ();
}
Private void listBox1_SelectedIndexChanged (object sender, EventArgse)
{
If (this. listBox1.SelectedItem! = Null)
{
Text = this. listBox1.SelectedItem. ToString ();
Index = this. listBox1.SelectedIndex;
Form2 form2 = new Form2 (text );
// Register the MyEvent event of the form2_MyEvent Method
Form2.MyEvent + = new MyDelegate (form2_MyEvent );
Form2.Show ();
}
}
// Process
Void form2_MyEvent (string text)
{
This. listBox1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.