Three questions I might need your help with.
1) When I read the book as a reference book, it just mentions about components and controls. The question is what is control and what is component?
2) Well...I tried to use TryParse but the result is 0 if the user enters some junk, what I want to display is the null value , not 0 within the label, which is what I use to display the result in text format.
(I know how TryParse works because it cannot parse the value, it return false, and the value 0 is the default value, which is created by the constructor).
3) In console, if you do something like the codes below, if the users enter junk, the invalid message is displayed. But in window form, I cannot do the same. I have to use ShowMessage method to display the invalid input message. I know it is possible to use Label to display the message, but HOW?
int i; bool result; String x; Console.Write("Please enter a number: "); x = Console.ReadLine(); result = int.TryParse(x, out i); if(result == false) Console.Write("\nThis is invalid input);
Here is the code for Window Form
// text is the properties of form, button, label, and textbox. //lblOutput is the label text property // txtInteger and txtInteger2 are the name // of the textboxes. bool result_x, result_i; int i, x, result; result_i = int.TryParse(txtInteger.text, out i); result_x = int.TryParse(txtInteger2.text, out x); if(!result_i || !result_x) lblOutput.text = "This is invalid input."; result = (i + x) / 2; lblOutput.text = result.ToString();
4) Question is why do we have to use text property following the name of textbox and label?
- The last lblOutput.text works and display the proper result. However, the statement if(!result_i || !result_x) lblOutput.text = "This is invalid input."; makes the program crash. I am just wondering why the bottom lblOutput works but the if(!result_i || !result_x) lblOutput.text = "This is invalid input."; won't work?