fursty

C# Celsius F

Oct 8th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 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 upr3c
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  21. {
  22. if (textBox1.Text != "")
  23. calc();
  24. }
  25.  
  26. private void textBox1_TextChanged(object sender, EventArgs e)
  27. {
  28. if (textBox1.Text != "")
  29. calc();
  30. }
  31. void calc()
  32. {
  33. double p, r;
  34. if (comboBox1.Text == "F")
  35. {
  36. p = double.Parse(textBox1.Text);
  37. r=(p-32)*5/9;
  38. textBox2.Text = r.ToString();
  39. }
  40. if (comboBox1.Text == "C")
  41. {
  42. p = double.Parse(textBox1.Text);
  43. r = p*9/5+32;
  44. textBox2.Text = r.ToString();
  45. }
  46. }
  47. private void Form1_Load(object sender, EventArgs e)
  48. {
  49. comboBox1.Items.Add("F");
  50. comboBox1.Items.Add("C");
  51. comboBox1.SelectedIndex = 0;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment