我在groupBox里添加了5个radioButton.它有没有一个属性指明选了那个radioButton? 这样可以减少写radioButton 的 checked .
解决方案 »
- 现有一个对象数组,如何按照不同字段对其排序?
- C#里截取字符串问题(紧急,在线等!!!)
- 系统日志处理为什么要用线程呢?
- 我有VS2005k(c#)做了一个C/S模式的小程序,为什么打包完了以后在别的机子是运行时有这个错误,怎么办!!!
- wince问题,高手近来看看。C#调用ocx(c++)
- 求正则表达式:除了汉字以外,所有字符的正则表达式
- 求指教~
- 这个获取Cpu的例子,有什么问题吗?为什么在我的机器上获取不到
- .net连接数据库问题 急急!!!!!!!!!急急!!!!!!!!!!
- 如何实现历史记录的导入导出功能
- 关于设计数据库表之间的关系
- foreach问题求救(System.NullReferenceException: 未将对象引用设置到对象的实例)
完了把其他的单击事件指定到那个写好的事件里
通过判断sender来执行各自的方法
{
if (groupBox1.Controls[i] is RadioButton)
{
RadioButton temp = (RadioButton) groupBox1.Controls[i];
if (temp.Checked)//判断是否选中
textBox2.Text= temp.Name;//这个可以自己改
}
}
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(48, 24);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(88, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = "radioButton1";
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(48, 56);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(88, 16);
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "radioButton2";
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);事件中写
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
if (sender.Equals(radioButton1))
{
textBox1.Text = "1";
}
if (sender.Equals(radioButton2))
{
textBox1.Text = "2";
}
}
简单明了
“先写1个radioButton的单击事件
完了把其他的单击事件指定到那个写好的事件里
通过判断sender来执行各自的方法”没有必要写什么循环来遍历,浪费时间。
给你参数(object sender, System.EventArgs e)就是给你用的