Question
I could really use some help with this assignment! The program must be in C#, and must be a form. Please make it as easy
I could really use some help with this assignment!
The program must be in C#, and must be a form. Please make it as easy as possible as I am new to programming!
---------------------------------------------------------------------
In this exercise, youll add code to a form that converts the value the user enters based on the selected conversion type.
The application should handle the following conversions:
From To Conversion
Miles Kilometers 1 mile = 1.6093 kilometers
Kilometers Miles 1 kilometer = 0.6214 miles
Feet Meters 1 foot = 0.3048 meters
Meters Feet 1 meter = 3.2808 feet
Inches Centimeters 1 inch = 2.54 centimeters
Centimeters Inches 1 centimeter = 0.3937 inches
1. Open the LengthConversionsStart project in the Assignment8\Ex1_LengthConversions directory. Display the code for the form, and notice the rectangular array whose rows contain the value to be displayed in the combo box, the text for the labels that identify the two text boxes, and the multiplier for the conversion as shown above.
2. Set the DropDownStyle property of the combo box so the user must select an item from the list.
3. Add code to load the combo box with the first element in each row of the rectangular array, and display the first item in the combo box when the form is loaded.
4. Add code
1.to change the labels for the text boxes,
2.clear the calculated length,
3.and move the focus to the entry text box when the user selects a different item from the combo box.
5. Test the application to be sure the conversions are displayed in the combo box, the first conversion is selected by default, and the labels change appropriately when a different conversion is selected.
6. Add code to calculate and display the converted length when the user clicks the Calculate button.
To calculate the length, you can get the index for the selected conversion and then use that index to get the multiplier from the array. Test the application to be sure this works correctly.
7. Add code to check that the user enters a valid decimal value for the length.
8. Then, test the application one more time to be sure the validation works correctly.
Suggested methods to implement are commented, but feel free to make your own.
--------------------------------------------------------------------------------
The code that needs to be modified:
namespace Conversions { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
string[,] conversionTable = { {"Miles to kilometers", "Miles", "Kilometers", "1.6093"}, {"Kilometers to miles", "Kilometers", "Miles", "0.6214"}, {"Feet to meters", "Feet", "Meters", "0.3048"}, {"Meters to feet", "Meters", "Feet", "3.2808"}, {"Inches to centimeters", "Inches", "Centimeters", "2.54"}, {"Centimeters to inches", "Centimeters", "Inches", "0.3937"} };
//private void Form1_Load(object sender, EventArgs e) //{ // ...//this is where you need to make the most //}
//private void cboConversions_SelectedIndexChanged(object sender, EventArgs e) //{ // ... //}
//private void btnCalculate_Click(object sender, EventArgs e) //{ // ... //}
public bool IsPresent(TextBox textBox, string name) { if (textBox.Text == "") { MessageBox.Show(name + " is a required field.", "Entry Error"); textBox.Focus(); return false; } return true; }
public bool IsDecimal(TextBox textBox, string name) { try { Convert.ToDecimal(textBox.Text); return true; } catch (FormatException) { MessageBox.Show(name + " must be a decimal number.", "Entry Error"); textBox.Focus(); return false; } }
private void btnExit_Click(object sender, EventArgs e) {
this.Close(); } } }
------------------------------------------------------------------------
THANKS!
Conversions Conversion Meters to feet Meters Feet 640.40 Calculate Exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started