我需要在程序中动态加载n个RadioButton 控件(n不确定,根据程序的运行情况而定),但是我要处理这n个RadioButton 按钮的CheckedChanged事件,怎么写这些事件的处理过程啊(其实他们的处理过程都一样,就是把form里面的一个string类型的变量赋不同的值),因为n不确定,我怎么知道写多少个这样的
private void radioButton1_CheckedChanged(Object sender,
EventArgs e)
{
this.strTest = radioButton1.Text;
}
事件处理程序呢?
private void radioButton1_CheckedChanged(Object sender,
EventArgs e)
{
this.strTest = radioButton1.Text;
}
事件处理程序呢?
解决方案 »
- c#如何调用科大讯飞的DLL
- 如何学习C#
- 请教:写了一个Form组件,想要把组件名存入数据库的菜单表,当点击菜单时直接打开Form组件。
- 刚学习WCF有点不懂请大家帮忙指点下
- 请大家帮帮忙??
- 如何在使用DLL文件后,通过程序卸载使用的DLL文件?
- WPF,请问ClickOnce部署
- 在用水晶报表打印的时候,弹出打印机设置框。纸张规格每次默认是LETTER
- winform滚动条
- 为何 ConcurrentDictionary.Keys 的散列值一直在变?
- 1000求购类似于china.53trade.com 的源代码(c#)哪个大哥有的请联系,谢谢
- 求助,将十六进制文件转换成gb2312格式汉字
{
int i = 0;
RadioButton rb = new RadioButton();
rb.Location = new Point(10, rb.Height * 0);
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);
}void rb_CheckedChanged(object sender, EventArgs e)
{
}
void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
switch (rb.Text)
{
case "":
break;
default:
break;
}
}
}
void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
this.strTest = rb.Text;
}
}
{
}
所有的RadioButton 的处理函数都用这一个就可以也就是
private void button11_Click(object sender, EventArgs e)
{
int i = 0;
RadioButton rb = new RadioButton();
rb.Location = new Point(10, rb.Height * 0);
rb.CheckedChanged += new EventHandler(rb_CheckedChanged); RadioButton rb2 = new RadioButton();
rb2.Location = new Point(10, rb.Height * 1);
rb2.CheckedChanged += new EventHandler(rb_CheckedChanged);
...
RadioButton rbn = new RadioButton();
rbn.Location = new Point(10, rb.Height * n);
rbn.CheckedChanged += new EventHandler(rb_CheckedChanged);
}
也可以吧?
for(int i=0;i<10;i++)
{
RadioButton rb = new RadioButton();
rb.Location = new Point(10, rb.Height * i);
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);//都是一个事件处理方法
}
{
RadioButton rb = new RadioButton();
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);
This.Control.add(rb)
}void rb_CheckedChanged(object Sender, EventArgs e)
{
//这里判断到底是哪个RadioButton触发事件了
((RadioButton)Sender).属性.. <--这个就是触发事件的rb了
}