Advertisement
DrAungWinHtut

Checkbox and Radio Button in C#

Mar 9th, 2022
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.65 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.             lblLeft.Text = "km";
  23.             lblRight.Text = "miles";
  24.  
  25.  
  26.             cboCities.Text = "km to miles";        
  27.            
  28.             //combo box ထဲကို item အသစ်တစ်ခု ထည့်တာ
  29.             cboCities.Items.Add("km to miles"); //index = 0
  30.             cboCities.Items.Add("cm to inches"); //index = 1
  31.             cboCities.Items.Add("meter to miles"); //index = 2
  32.             cboCities.Items.Add("yard to meter"); //index = 2
  33.  
  34.             cboCities.SelectedIndex = 0; //km to miles
  35.  
  36.         }
  37.  
  38.         private void btnAddCity_Click(object sender, EventArgs e)
  39.         {
  40.             string sCity = txtCity .Text;
  41.             cboCities .Items.Add(sCity);
  42.         }
  43.  
  44.         private void cboCities_SelectedIndexChanged(object sender, EventArgs e)
  45.         {
  46.             if(cboCities.SelectedIndex == 0)
  47.             {
  48.                 lblLeft.Text = "km";
  49.                 lblRight.Text = "miles";                
  50.             }
  51.             else if(cboCities.SelectedIndex == 1)
  52.             {
  53.                 lblLeft.Text = "cm";
  54.                 lblRight.Text = "inches";              
  55.             }
  56.             else if (cboCities.SelectedIndex == 2)
  57.             {
  58.                 lblLeft.Text = "meter";
  59.                 lblRight.Text = "miles";
  60.             }
  61.             else if (cboCities.SelectedIndex == 3)
  62.             {
  63.                 lblLeft.Text = "yard";
  64.                 lblRight.Text = "meter";
  65.             }
  66.  
  67.         }
  68.  
  69.         private void btnCalculate_Click(object sender, EventArgs e)
  70.         {
  71.            
  72.             float fConst = 0.0f ; //f for float variable
  73.             float fLeft = float.Parse(txtLeft.Text);
  74.             if (cboCities.SelectedIndex == 0)
  75.             {
  76.                 fConst = 0.621371f;
  77.             }
  78.             else if (cboCities.SelectedIndex == 1)
  79.             {
  80.                 fConst = 0.393701f;
  81.             }
  82.             else if (cboCities.SelectedIndex == 2)
  83.             {
  84.                 fConst = 0.000621371f;
  85.             }
  86.             else if (cboCities.SelectedIndex == 3)
  87.             {
  88.                 fConst = 0.9144f;
  89.             }
  90.             float fAns = fConst * fLeft;
  91.             txtRight.Text = fAns.ToString();
  92.  
  93.         }
  94.  
  95.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  96.         {
  97.             Application .Exit ();
  98.         }
  99.  
  100.         private void btnMedicalTest_Click(object sender, EventArgs e)
  101.         {
  102.             int iScore = 100;
  103.             if(chkDrink .Checked)
  104.             {
  105.                 // iScore = iScore - 20;
  106.                 iScore -= 20;
  107.             }
  108.             if (chkSmoking.Checked)
  109.             {
  110.                 // iScore = iScore - 20;
  111.                 iScore -= 20;
  112.             }
  113.             if(rdoFemale .Checked )
  114.             {
  115.                 MessageBox.Show("Female");
  116.             }
  117.            else if (rdoMale .Checked)
  118.             {
  119.                 MessageBox.Show("Male");
  120.             }
  121.            else if (rdoUndefine .Checked)
  122.             {
  123.                 MessageBox.Show("Undefine");
  124.             }
  125.             txtMedicalResult .Text = iScore.ToString();
  126.  
  127.         }
  128.     }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement