2016-09-29 74 views
0

可以說我有每個單選按鈕不同的變量。我怎樣才能做到這一點?我搜索了互聯網,但沒有發現任何東西。如何在每個單選按鈕上添加變量?

radioButton1

int a = 1 
int b = 2 
int c = 3 

radioButton2

int a = 5 
int b = 4 
int c = 2 
+0

創建一個類或結構或一個元組,並將其存儲在RadioButton的Tag中。 – TaW

回答

0

它不清楚是什麼你問,但我想你想改變取決於檢查什麼單選按鈕整數的值。

int a, b, c; 
if (radioButton1.Checked) 
{ 
    a = 1, b = 2, c = 3; 
} 
else 
{ 
    a = 5, b = 4, c = 2; 
} 
0

創建用戶控件和類

public class { 

prop1 int var1 
{ 
set, get 
} 
prop2 int var2 
{ 
set, get 
} 
prop3 int var3 
{ 
set, get 
} 
} 
0

像TAW添加這些瓦爾的性能說:你可以擴展Button類和變量添加到它。不太確定語法,但它應該是這樣的,其中RadioButton是您想要擴展的類,而MyButton將是您的自定義類。

public class MyButton : RadioButton 
{ 

    public int a; 
    public int b; 
    public int c; 
} 

RadioButton的所有方法和屬性也將提供給您的新班級。你可以用方法擴展它來讀寫你的附加屬性a,bc

0
private void button1_Click(object sender, EventArgs e) 
     { 
      int a, b, c; 
      if (radioButton1.Checked == true) 
      { 
       a = 1; b = 2; c = 3; 
      } 
      if (radioButton2.Checked == true) 
      { 
       a = 5; b = 4; c = 2; 

      } 
     } 

,以及你可以使用同樣的事情radioButton1_CheckedChanged事件,將取決於你的需求:)祝你好運!

相關問題