c#checkbox 问题 10

有一个TEXTbox,一个Label,还有2个button1和button2;在TEXTbox输入字,点击一次button1,界面上就会生成一个checkbox,chec... 有一个TEXTbox ,一个Label,还有2个button1 和button2;
在TEXTbox输入字,点击一次button1, 界面上就会生成一个checkbox,checkbox.text=textbox.text ,选择生成的checkbox。 再点击button2时,将被选中的checkbox的TEXT数值,在label内输出;

我原来问题不好描述,但问题大概就是这样子。 求高手帮忙搞定下,谢谢
点击多次 button1 ,然后选择,再点击button2
展开
 我来答
tangliang113
2011-05-06 · 超过12用户采纳过TA的回答
知道答主
回答量:44
采纳率:0%
帮助的人:32万
展开全部
protected void button1_click(object sender, EventArgs e){
CheckBox cb=new CheckBox();
cb.ID = "check" ;
Container.Controls.Add(cb);
check.Text=textbox.text ;
}
protected void button2_click(object sender, EventArgs e){
this.lable.text=check.text;

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wujiazhao1988
2011-05-06 · TA获得超过413个赞
知道小有建树答主
回答量:397
采纳率:0%
帮助的人:300万
展开全部

using System.Windows.Forms;

/*

 * Created by SharpDevelop.

 * User: jiacheo

 * Date: 2011/5/6

 * Time: 23:32

 * 

 * To change this template use Tools | Options | Coding | Edit Standard Headers.

 */

namespace zhidao

{

partial class MainForm

{

/// <summary>

/// Designer variable used to keep track of non-visual components.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Disposes resources used by the form.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing) {

if (components != null) {

components.Dispose();

}

}

base.Dispose(disposing);

}

/// <summary>

/// This method is required for Windows Forms designer support.

/// Do not change the method contents inside the source code editor. The Forms designer might

/// not be able to load this method if it was changed manually.

/// </summary>

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.label1 = new System.Windows.Forms.Label();

this.SuspendLayout();

// 

// textBox1

// 

this.textBox1.Location = new System.Drawing.Point(12, 12);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(100, 21);

this.textBox1.TabIndex = 0;

// 

// button1

// 

this.button1.Location = new System.Drawing.Point(128, 12);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 1;

this.button1.Text = "button1";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.Button1Click);

// 

// button2

// 

this.button2.Location = new System.Drawing.Point(12, 51);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(75, 23);

this.button2.TabIndex = 2;

this.button2.Text = "button2";

this.button2.UseVisualStyleBackColor = true;

this.button2.Click += new System.EventHandler(this.Button2Click);

// 

// label1

// 

this.label1.Location = new System.Drawing.Point(116, 51);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(100, 23);

this.label1.TabIndex = 3;

this.label1.Text = "label1";

// 

// MainForm

// 

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(409, 117);

this.Controls.Add(this.label1);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Controls.Add(this.textBox1);

this.Name = "MainForm";

this.Text = "zhidao";

this.ResumeLayout(false);

this.PerformLayout();

}

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox textBox1;

private CheckBox checkBox1 ;

void Button1Click(object sender, System.EventArgs e)

{

checkBox1 = new CheckBox();

checkBox1.Text = textBox1.Text;

checkBox1.Location = new System.Drawing.Point( 220, 12 );

this.Controls.Add(checkBox1);

}

void Button2Click(object sender, System.EventArgs e)

{

if(checkBox1!=null && checkBox1.Checked){

label1.Text = checkBox1.Text;

}

}

}

}

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式