Advertisement
DrAungWinHtut

Unit Converter CS

Mar 8th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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 _2022030201_CS_Array_Tutorial
  12. {
  13. public partial class frmUItest : Form
  14. {
  15. public frmUItest()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void frmUItest_Load(object sender, EventArgs e)
  21. {
  22. cboCities.Text = "km to miles";
  23. lblLeft.Text = "km";
  24. lblRight.Text = "miles";
  25.  
  26.  
  27. cboCities.Items.Add("km to miles");
  28. cboCities.Items.Add("cm to inches");
  29.  
  30. }
  31.  
  32. private void btnAddCity_Click(object sender, EventArgs e)
  33. {
  34. string sCity = txtCity .Text;
  35. cboCities .Items.Add(sCity);
  36. }
  37.  
  38. private void cboCities_SelectedIndexChanged(object sender, EventArgs e)
  39. {
  40. if(cboCities.SelectedIndex == 0)
  41. {
  42. lblLeft.Text = "km";
  43. lblRight.Text = "miles";
  44.  
  45. }
  46. else if(cboCities.SelectedIndex == 1)
  47. {
  48. lblLeft.Text = "cm";
  49. lblRight.Text = "inches";
  50.  
  51. }
  52.  
  53. }
  54.  
  55. private void btnCalculate_Click(object sender, EventArgs e)
  56. {
  57.  
  58. float fConst = 0.0f;
  59. float fLeft = float.Parse(txtLeft.Text);
  60. if (cboCities.SelectedIndex == 0)
  61. {
  62. fConst = 0.62f;
  63. }
  64. else if (cboCities.SelectedIndex == 1)
  65. {
  66. fConst = 0.39f;
  67. }
  68. float fAns = fConst * fLeft;
  69. txtRight.Text = fAns.ToString();
  70.  
  71. }
  72. }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement