Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Assessment5A
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- //On initialization of the form, the following code will execute, and create three columns
- //The below line of code adds the headers to each column respectively
- lstChart.Items.Add("F" + "\t" + "C" + "\t" + "K");
- double y;
- double z;
- //Loops code to fill in all three columns with the correct temperature calculations, rounding to one decimal place when outputted
- for (double x = 32.0; x <= 212.0; x++)
- {
- y = (x - 32) * 5 / 9;
- z = (y + 273);
- lstChart.Items.Add((x.ToString()) + "\t" + (y.ToString("n1")) + "\t" + (z.ToString("n1")));
- }
- }
- private void btnExit_Click(object sender, EventArgs e)
- //Closes the application when the Exit button is clicked by the user
- {
- this.Close();
- }
- private void btnCalc_Click(object sender, EventArgs e)
- {
- //When a value is entered, the program will calculate the Celsius and Kelvin conversions below, and display them
- double userIn;
- double celCon;
- double kelCon;
- if (double.TryParse(txtUser.Text, out userIn))
- {
- celCon = (userIn - 32) * 5 / 9;
- kelCon = celCon + 273;
- lblOutCel.Text = (celCon.ToString("n1"));
- lblOutKel.Text = (kelCon.ToString("n1"));
- }
- else
- {
- //If the user does not enter a valid number(double) value, as the code cannot parse it, will display below message and prompt a
- //different input; Data Validation
- MessageBox.Show("Please enter a valid number!");
- txtUser.Text = "";
- txtUser.Focus();
- }
- }
- private void btnReset_Click(object sender, EventArgs e)
- {
- //Resets all fields to clear
- txtUser.Text = "";
- txtUser.Focus();
- lblOutKel.Text = "";
- lblOutCel.Text = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement