c#使用VS2008 winForm编程中RadioButton的用法

我正在用VS2008编写一个注册界面,其中有性别男女两项,使用RadioButton控件分别表示男和女,点击RadioButton1(男)注册成功后在SQl2000数据库表中Sex一栏显示“男”(数据库已连接),反之,点击RadioButton1(女)注册成功后在Sex一栏中显示“女”,其他功能都实现了,因为刚学c#,对RadioButton的用法不是很清楚,在线等!!望高手赐教!!

有两种方法

1、在VS2008中依次选中每一个RadioButton右击--“属性”在属性中找到CheckedChange事件,为其指定为新写的事件。如下图:

2、在初始化窗体的时候添加如下代码:

      

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-01-19
在窗体上拖入两个RadioButton控件,分别起名为 radMan和radGril
然后在代码中利用以下代码即可获取,下面是一个三元运算符。
意思是,如果radMan被选中,则返回radMan的文本,因为我设置了radMan.Text为“男”,radGril.Text为“女”,所以如果radMan.Checked为false(即未选中状态),则性别为女。
string sex = radMan.Checked ? radMan.Text : radGril.Text;
第2个回答  2010-01-19
先添加两个RadioButton控件,其text属性设成男,女。还要记住他们的GroupName属性给他们随便起个名字,两个RadioButton中的GroupName属性名都设成一样的,不然,两个按钮都可以点上,
然后就是往数据库添加了:
先定义一个变量(sex)记录往数据库插的的男或是女!

string sex;

if (RadioButton1.Checked==true)//如果是男的被选中的话
{
sex = "男";
}
else
{
sex = "女";
}

往数据库插的话相信你就没问题了吧!
第3个回答  2010-01-19
取RadioButton.Text然后更新数据库就行了
第4个回答  推荐于2016-05-06
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton1.Checked==true)
{
radioButton2.Checked=false;
}
}

private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton2.Checked==true)
{
radioButton1.Checked=false;
}
}

private void button5_Click(object sender, System.EventArgs e)
{
string sex="";
if(radioButton1.Checked==true)
{
sex=radioButton1.Text;
}
if(radioButton2.Checked==true)
{
sex=radioButton2.Text;
}本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网