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 DistanceConverterZafar
- {
- public partial class Form1 : Form
- {
- public object Messagebox { get; private set; }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- FromListBox.Items.Add("Inch");
- FromListBox.Items.Add("Feet");
- FromListBox.Items.Add("Yard");
- ToDistanceListBox.Items.Add("Inch");
- ToDistanceListBox.Items.Add("Feet");
- ToDistanceListBox.Items.Add("Yard");
- }
- private void ConvertButton_Click(object sender, EventArgs e)
- {
- {
- int distance, final; //variable to store user input
- string option, option2; //variables to store items from each listbox
- if (int.TryParse(NumberTextBox.Text, out distance)) //to prevent exemption
- {
- if (FromListBox.SelectedIndex != -1 &&
- ToDistanceListBox.SelectedIndex != -1)//to prevent exemption for listboxes
- {
- option = FromListBox.SelectedItem.ToString();
- option2 = ToDistanceListBox.SelectedItem.ToString();
- if (option == "Inches" && option2 == "Inches")
- {
- AnswerLabel.Text = distance.ToString();
- }
- else if (option == "Inches" && option2 == "Feet")
- {
- final = distance / 12;
- AnswerLabel.Text = final.ToString();
- }
- else if (option == "Feet" && option2 == "Feet")
- {
- AnswerLabel.Text = distance.ToString();
- }
- else if (option == "Feet" && option2 == "Inches")
- {
- final = distance * 12;
- AnswerLabel.Text = final.ToString();
- }
- }
- else
- {
- MessageBox.Show("Please select an item from the list");
- }
- }
- else
- {
- MessageBox.Show("Please enter a number!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement