c#checkbox 问题 10
在TEXTbox输入字,点击一次button1, 界面上就会生成一个checkbox,checkbox.text=textbox.text ,选择生成的checkbox。 再点击button2时,将被选中的checkbox的TEXT数值,在label内输出;
我原来问题不好描述,但问题大概就是这样子。 求高手帮忙搞定下,谢谢
点击多次 button1 ,然后选择,再点击button2 展开
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;
}
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;
}
}
}
}