Programming third step to increase response to user event code
The final step is to add a method to capture the button click
Event. Here is the button click Code from Celsius to Fahrenheit:
private void Bnctof_click (Object sender,
EventArgs e) {
Double dtempcel = 0;
Double Dtempfah = 0;
try {dtempcel = TTempCel.Text.ToDouble ();}
catch (Exception) {
Ttempcel.clear ();
Ttempfah.clear ();
Return
}
Dtempfah = 1.8*dtempcel+32;
Ttempfah.text = Dtempfah.tostring ();
Ttempfah.focus ();
Ttempfah.selectionstart = 0;
ttempfah.selectionlength = 0;
Ttempcel.focus ();
Ttempcel.selectionstart = 0;
ttempcel.selectionlength = 0;
}
The following is the code for the Fahrenheit button, which will accomplish the same task, but is just the opposite
The processing:
private void Bnftoc_click (Object sender,
EventArgs e) {
Double dtempcel = 0;
Double Dtempfah = 0;
try {Dtempfah = TTempFah.Text.ToDouble ();}
catch (Exception) {
Ttempcel.clear ();
Ttempfah.clear ();
Return
}
Dtempcel = (dTempFah-32)/1.8;
Ttempcel.text = Dtempcel.tostring ();
Ttempcel.focus ();
Ttempcel.selectionstart = 0;
ttempcel.selectionlength = 0;
Ttempfah.focus ();
Ttempfah.selectionstart = 0;
ttempfah.selectionlength = 0;
}
Next, we need to link the appropriate Click event Capture method with the Click event of the button
Get up. To complete this step, we place the following two lines in the constructor of the class:
Bnctof.click + = new EventHandler
(This.bnctof_click);
Bnftoc.click + = new EventHandler
(This.bnftoc_click);
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