为“显示”按钮编写“单击”(Click)事件处理代码,实现在TextBox中显示所填与所选信息(效果如下图所示)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为“显示”按钮编写“单击”(Click)事件处理代码,实现在TextBox中显示所填与所选信息(效果如下图所示)相关的知识,希望对你有一定的参考价值。
参考技术A private void button1_Click(object sender, EventArgs e)string a="";
string b="";
if (radioButton1.Checked)
a = "男";
else
a = "女";
if (checkBox1.Checked)
b = b + checkBox1.Text;
if (checkBox2.Checked)
b = b + checkBox2.Text;
if (checkBox3.Checked)
b = b + checkBox3.Text;
if (checkBox4.Checked)
b = b + checkBox4.Text;
textBox3.Text = "姓名" + textBox1.Text + "班级" + textBox2.Text + "性别" + a + "爱好" + b;
本回答被提问者和网友采纳 参考技术B // 姓名
TextBox uname = new TextBox();
uname.Text = "zhangsan";
// 班级
TextBox uclass = new TextBox();
uclass.Text = "073361";
// 性别
RadioButton usex = new RadioButton();
usex.Text = "男";
RadioButton usext = new RadioButton();
usext.Text = "女";
// 爱好
CheckBox ulove = new CheckBox();
ulove.Text = "爱好1";
CheckBox ulove1 = new CheckBox();
ulove1.Text = "爱好2";
CheckBox ulove2 = new CheckBox();
ulove2.Text = "爱好3";
CheckBox ulove3 = new CheckBox();
ulove3.Text = "爱好4";
// 显示
Button Show = new Button();
Show.Text = "显示";
Show.Click += new EventHandler(ShowClick);
// 显示结果
TextBox ShowText = new TextBox();
// 你想要的方法
private void ShowClick(object sender, EventArgs e)
ShowText.Text =
"姓名为:" + uname.Text
+ " 班级为:" + uclass.Text
+ " 性别为:";
if (usex.CanSelect == true)
ShowText.Text += usext.Text;
else
ShowText.Text += ulove.Text;
ShowText.Text += " 爱好为:";
if (ulove.Checked == true) ShowText.Text += ulove.Text;
if (ulove1.Checked == true) ShowText.Text += ulove1.Text;
if (ulove2.Checked == true) ShowText.Text += ulove2.Text;
if (ulove3.Checked == true) ShowText.Text += ulove3.Text;
参考技术C 你保证是弄错了
以上是关于为“显示”按钮编写“单击”(Click)事件处理代码,实现在TextBox中显示所填与所选信息(效果如下图所示)的主要内容,如果未能解决你的问题,请参考以下文章