vc#中5个radiobutton,其中一个被选中,按button1则选中的radiobutton.text值变为2y.代码怎么写 10

 我来答
蟑螂111119e0b6da
2014-01-14 · TA获得超过220个赞
知道答主
回答量:138
采纳率:0%
帮助的人:38.5万
展开全部
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;
using System.Windows.Forms;
namespace FormStopwatch { public class Form1 : Form { private RadioButton radioButton2; private Button button1; private RadioButton radioButton1; public Form1() { InitializeComponent(); }
private void InitializeComponent() { this.radioButton1 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Location = new System.Drawing.Point(137, 58); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(95, 16); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "radioButton1"; this.radioButton1.UseVisualStyleBackColor = true; // // radioButton2 // this.radioButton2.AutoSize = true; this.radioButton2.Location = new System.Drawing.Point(120, 128); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(95, 16); this.radioButton2.TabIndex = 1; this.radioButton2.TabStop = true; this.radioButton2.Text = "radioButton2"; this.radioButton2.UseVisualStyleBackColor = true; // // button1 // this.button1.Location = new System.Drawing.Point(146, 181); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 2; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.button1); this.Controls.Add(this.radioButton2); this.Controls.Add(this.radioButton1); this.Name = "Form1"; this.ResumeLayout(false); this.PerformLayout();
}
private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked) radioButton1.Text = "y2"; else if (radioButton2.Checked) radioButton2.Text = "y2"; } }}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
allenlew312
2014-01-14 · TA获得超过297个赞
知道小有建树答主
回答量:99
采纳率:0%
帮助的人:73.4万
展开全部

双击你的button1,写它的消息响应:

        private void button1_Click(object sender, EventArgs e)
        {
            RadioButton[] rbtns = new RadioButton[]
                {radioButton1, radioButton2, radioButton3, radioButton4, radioButton5};
            foreach (RadioButton radioButton in rbtns)
            {
                if (radioButton.Checked)
                {
                    radioButton.Text = "2y";
                }
            }
        }

代码已验证过,符合要求

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xmandlp
2014-01-14 · TA获得超过484个赞
知道小有建树答主
回答量:498
采纳率:0%
帮助的人:305万
展开全部
在button1的click事件中写如下代码就可以了:
//form1是那几个radiobutton所属的父级控件,如果你把radiobutton放在一个panel里 那么form1改成那个panel的Name属性就可以了
foreach (Control c in form1.Controls)
{
if (c is RadioButton && ((RadioButton)c).Checked == true)
{
((RadioButton)c).text=”2y“;
break;
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式