积极答复者
高手们给个将多个CHECKBOX改为单选的示例,谢谢.

问题
答案
-
你好
不好意思..上面的教學C#版本有些問題..現在已經解決了..c=c_loopVariable其實是沒有意思的應該是自動轉換器籨VB轉做C#時出現問題
以下是我的Sample
希望可以幫到你
//this function is used to clear the other check box and make it look like radio button private void PretendRadio(object c) { foreach (object c_loopVariable in groupBox1.Controls) { if ((c_loopVariable) is CheckBox) { ((CheckBox) c_loopVariable).Checked = false ; } } //check the original checkbox ((CheckBox)c).Checked = true; } private void checkBox1_Click(object sender, EventArgs e) { //call the clear check box method PretendRadio(sender); } private void checkBox2_Click(object sender, EventArgs e) { PretendRadio(sender); } private void checkBox3_Click(object sender, EventArgs e) { PretendRadio(sender); }
以下是我的Sample不知道能不能解體你的問題 ..或者其他高人有更好的方法解決
Please correct me if my concept is wrong.
Chi
- 已标记为答案 呆oO 2012年5月1日 0:34
全部回复
-
麻烦高手给个示例 ,你给的下面的网址我看了,结果也没运行成功.主要原因是因为我水平有限.不知道下面那个"C"是干嘛用的.希望哪位高手给简明完善一下.谢谢
以下转自网站:
解決方法十分簡單…
在可以的情況下.
所相同性質的控件..放在GroupBox或Panel中..
以便管理..
E.G.
我建立一個Panel 改名為”p_ReportSettings”
入面建立了很多的CheckBox..用來設定那一個Report將會被Generate之後在Panel外建立另一個CheckBox來 作Check/Uncheck All CheckBox之用
之後便可以加入以下的Code用來找出所有在Panel 入有CheckBox 屬性 的控件出來了
E.G.0304050607080910111213private
void
cb_ReportCheckAll_CheckedChanged(
object
sender, EventArgs e)
{
bool
CheckAll = !cb_ReportCheckAll.Checked;
foreach
(
object
c_loopVariable
in
pl_ReportSettings.Controls) {
c = c_loopVariable;
if
((c)
is
CheckBox) {
((CheckBox)c).Checked = CheckAll;
}
}
}
C#初学者!~~~
- 已编辑 呆oO 2012年4月30日 12:20
-
你好
不好意思..上面的教學C#版本有些問題..現在已經解決了..c=c_loopVariable其實是沒有意思的應該是自動轉換器籨VB轉做C#時出現問題
以下是我的Sample
希望可以幫到你
//this function is used to clear the other check box and make it look like radio button private void PretendRadio(object c) { foreach (object c_loopVariable in groupBox1.Controls) { if ((c_loopVariable) is CheckBox) { ((CheckBox) c_loopVariable).Checked = false ; } } //check the original checkbox ((CheckBox)c).Checked = true; } private void checkBox1_Click(object sender, EventArgs e) { //call the clear check box method PretendRadio(sender); } private void checkBox2_Click(object sender, EventArgs e) { PretendRadio(sender); } private void checkBox3_Click(object sender, EventArgs e) { PretendRadio(sender); }
以下是我的Sample不知道能不能解體你的問題 ..或者其他高人有更好的方法解決
Please correct me if my concept is wrong.
Chi
- 已标记为答案 呆oO 2012年5月1日 0:34