vc#中5个radiobutton,其中一个被选中,按button1则选中的radiobutton.text值变为2y.代码怎么写 10
3个回答
展开全部
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"; } }}
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"; } }}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
双击你的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";
}
}
}
代码已验证过,符合要求
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在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;
}
}
//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;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询