1. Open Visual Studio 2013. Open new project.
2. Select Windows Phone Application and then choose C# as programming language.
3. Name the project as ADDNUM and specify the address of your folder.
4. In the main window design the form as shown below.
Here we have used three textbox and one button. These controls are named accordingly. Labels are provided against each control to increase readability. Our aim is to accept two numbers from the first two textboxes and display the sum of these two numbers in the third textbox result. This task should be performed as soon as we press the Add button. hence we need to write the code in the Add button_click event.The code is given below.
Double click the add button to get the code area. Then write the following code in the button click event.
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
float fn = float.Parse(txtNumber1.Text);
float sn = float.Parse(txtNumber2.Text);
float res = fn + sn;
txtResult.Text = res.ToString();
}
j
Here, fn and sn are two variables to hold the values of two numbers. Float.parse is used to typecast the contents of textbox1 and textbox2 into float values because fn and sn are float variables. res is another variable to hold the result. The result is displayed in the third textbox. Isn't it simple!!
No comments:
Post a Comment