Exemplu pentru a folosi butoane radio in C# Sharp

Configurare noua (How To)

Situatie

Exemplu pentru a folosi butoane radio in C# Sharp.

Acesta este un exemplu prin care folosim butoanele radio cu text predefinit pentru a afisa un mesaj atunci cand actionam butonul Selectat.

 

Solutie

Pasi de urmat
  1. Se deschide Microsoft Visual Studio, proiect nou, windows, windows application form:
1_MessageBox_in_C_Sharp_diferite_proprietati

2. Se adauga butoane radio si butonul de actionare:

  • radio button – Rosu , Albastru , Verde , Galben;
  • buton – Selectat;
1_Butoane_Radio_efecte_simplu_exemplu

3. Se introduce codul cu actionare pentru fiecare radiobutton selectat atunci cand se apasa “Selectat”:

private void button1_Click(object sender, EventArgs e)

{

string Culoare = “”;

if (radioButton1.Checked)

{

Culoare = radioButton1.Text;

}

if (radioButton2.Checked)

{

Culoare = radioButton2.Text;

}

if (radioButton3.Checked)

{

Culoare = radioButton3.Text;

}

if (radioButton4.Checked)

{

Culoare = radioButton4.Text;

}

MessageBox.Show(Culoare);

 

Unde va apara:

  • cand radio button “Rosu” este selectat si se da click pe butonul “Selectat”;
2_Butoane_Radio_efecte_simplu_exemplu
  • cand radio button “Albastru” este selectat si se da click pe butonul “Selectat”;
3_Butoane_Radio_efecte_simplu_exemplu
  • cand radio button “Verde” este selectat si se da click pe butonul “Selectat”;
4_Butoane_Radio_efecte_simplu_exemplu
  • cand radio button “Galben” este selectat si se da click pe butonul “Selectat”;
5_Butoane_Radio_efecte_simplu_exemplu

Tip solutie

Permanent

Voteaza

(26 din 59 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?