Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace DistanceConverterZafar
  12. {
  13. public partial class Form1 : Form
  14. {
  15.  
  16. public object Messagebox { get; private set; }
  17.  
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void Form1_Load(object sender, EventArgs e)
  24. {
  25. FromListBox.Items.Add("Inch");
  26. FromListBox.Items.Add("Feet");
  27. FromListBox.Items.Add("Yard");
  28.  
  29.  
  30. ToDistanceListBox.Items.Add("Inch");
  31. ToDistanceListBox.Items.Add("Feet");
  32. ToDistanceListBox.Items.Add("Yard");
  33.  
  34. }
  35.  
  36. private void ConvertButton_Click(object sender, EventArgs e)
  37. {
  38. {
  39. int distance, final; //variable to store user input
  40. string option, option2; //variables to store items from each listbox
  41.  
  42. if (int.TryParse(NumberTextBox.Text, out distance)) //to prevent exemption
  43. {
  44. if (FromListBox.SelectedIndex != -1 &&
  45. ToDistanceListBox.SelectedIndex != -1)//to prevent exemption for listboxes
  46. {
  47. option = FromListBox.SelectedItem.ToString();
  48. option2 = ToDistanceListBox.SelectedItem.ToString();
  49.  
  50. if (option == "Inches" && option2 == "Inches")
  51. {
  52. AnswerLabel.Text = distance.ToString();
  53. }
  54. else if (option == "Inches" && option2 == "Feet")
  55. {
  56. final = distance / 12;
  57. AnswerLabel.Text = final.ToString();
  58. }
  59. else if (option == "Feet" && option2 == "Feet")
  60. {
  61. AnswerLabel.Text = distance.ToString();
  62. }
  63. else if (option == "Feet" && option2 == "Inches")
  64. {
  65. final = distance * 12;
  66. AnswerLabel.Text = final.ToString();
  67. }
  68. }
  69. else
  70. {
  71. MessageBox.Show("Please select an item from the list");
  72. }
  73. }
  74. else
  75. {
  76. MessageBox.Show("Please enter a number!");
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement