A new delegate program! Objective To consolidate! Delegate usage!

Source: Internet
Author: User

The Code is as follows: Public Delegate void selectlable (string E );
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
Checkbox1.enabled = false;
Checkbox2.enabled = false;
Checkbox3.enabled = false;
If (STR = "")
{
Label1.text = "enter a string! ";
}
}
Public String STR {get {return textbox1.text. tostring () ;}set {STR = value ;}}

Private void button#click (Object sender, eventargs E)
{
If (checkbox1.checked = true & checkbox2.checked = false & checkbox3.checked = false)
{
Label1.forecolor = system. Drawing. color. Red;
}
Else if (checkbox1.checked = false & checkbox2.checked = true & checkbox3.checked = false)
{
Label1.forecolor = system. Drawing. color. Green;
}
Else if (checkbox1.checked = false & checkbox2.checked = false & checkbox3.checked = true)
{
Label1.forecolor = system. Drawing. color. Black;
}
Else
{
Label1.text = STR;
}
}
Public event selectlable onselectlable;
Private void radiobutton1_checkedchanged (Object sender, eventargs E)
{
Try
{
Checkbox1.checked = radiobutton1.checked;
Checkbox2.checked = false;
Checkbox3.checked = false;
If (radiobutton1! = NULL)
{
Onselectlable (radiobutton1.checked. tostring ());
}
}
Catch {
Label1.text = STR;
}
}

Private void radiobutton2_checkedchanged (Object sender, eventargs E)
{
Try
{
Checkbox1.checked = false;
Checkbox2.checked = radiobutton2.checked;
Checkbox3.checked = false;
If (radiobutton2! = NULL)
{
Onselectlable (radiobutton2.checked. tostring ());
}
}
Catch {
Label1.text = STR;
}

}

Private void radiobutton3_checkedchanged (Object sender, eventargs E)
{
Try
{
Checkbox1.checked = false;
Checkbox2.checked = false;
Checkbox3.checked = radiobutton3.checked;
If (radiobutton3! = NULL)
{
Onselectlable (radiobutton3.checked. tostring ());
}
}
Catch {
Label1.text = STR;
}

}

Private void button2_click (Object sender, eventargs E)
{
Try
{
Radiobutton1.checked = false;
Radiobutton2.checked = false;
Radiobutton3.checked = false;

}
Catch
{
STR = "data has been cleared! ";
Label1.text = STR;
}
}
}

 

The interface is as follows:

 

 

When you click Cancel, you will find that you do not need to repeatedly write the checkbox status, but directly write radiobutton to clear it! The input box is not cleared. Sorry ~ Haha ~ But it's good!

The function of the delegate function is that when the following radiobutton is selected, the above checkbox will be moved. Maybe you will say, Who is checkbox1.checked = true in radiobutton;
Checkbox2.checked = false;
Checkbox3.checked = false;

Why checkbox1.checked = false;
Checkbox2.checked = false;
Checkbox3.checked = radiobutton3.checked;
If (radiobutton3! = NULL)
{
Onselectlable (radiobutton3.checked. tostring ());
}

And handle exceptions! It's troublesome. Wait, friend. You will come back to write me when you call this function. This is the benefit of writing your own time and calling the delegate function. If there are too many, I will not explain it!

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.