( 5 Points ) Open Visual Studio and create a new Window Application Project. Nam
ID: 668580 • Letter: #
Question
(5 Points) Open Visual Studio and create a new Window Application Project. Name the Project Lab2. NOTE: Ensure that C# is the programming language selected.
(5 Points) Make sure the form is named Lab2. Change the Forms Text property to “Currency Converter”. Re-size the form to Height = 180 and Width = 480.
(10 Points) Add 2 Text Boxes and 2 Labels to the form and position them similar to the image example seen on the first page of this Lab:
Change the Name of the first label to: labelAmount
Change the Text property of the labelName to: "Please enter the amount to be converted to US dollars"
Change the Name of the second label to: labelCurrency
Change the Text property of the labelAge to: "Please enter a currency"
Change the Name of the First Text box to: textBoxAmount
Change the Size of the textBoxAmount to: Width = 150, Height = 20
Change the Name of the Second Text box to: textBoxCurrency
Change the Size of the textBoxCurrency to: Width = 150, Height = 20
(10 Points) Add a button to the form and position it similar to the image example seen on the first page of this lab: Change the Name of the Button to: buttonShowNext and the text to: Next
(70 Points) Add code to the buttonShowNext that will do this following when the user clicks:
Create a Try and Catch block statement to store the code and trap the error if one occurs.
Declare a string variable called Currency
Declare a double variable called Amount
Then set the value of the Amount variable to the text value in the textBoxAmount
Then set the value of the Currency variable to the value in the textBoxCurrency
You will need to Parse the string stored in the text box (textBoxAmount) to a double in order to successfully assign its value to the double Amount variable.
Display a string in a Message Box similar to the following:
You have selected to convert "Amount" "Currency"
Finally, if the user enters bad data (non-numeric in the txtBoxAmount text box), a Message box pops up and says:
An error has occurred while parsing the amount entered!
3. Run your program to make sure that it works as expected.
4. Close your project and ZIP your entire project file. Then upload your project to CANVAS.
C#
Explanation / Answer
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
textBox3.Text = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)).ToString();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
textBox3.Text = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)).ToString();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.