首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

checkbox 单选 CS 构造的 不用JS写

2012-07-28 
checkbox 单选CS结构的 不用JS写private void InitializeComponent(){this.groupBox1 new System.Window

checkbox 单选 CS 结构的 不用JS写
private void InitializeComponent()
  {
  this.groupBox1 = new System.Windows.Forms.GroupBox();
  this.groupBox2 = new System.Windows.Forms.GroupBox();
  this.checkBox1 = new System.Windows.Forms.CheckBox();
  this.checkBox2 = new System.Windows.Forms.CheckBox();
  this.checkBox3 = new System.Windows.Forms.CheckBox();
  this.checkBox4 = new System.Windows.Forms.CheckBox();
  this.checkBox5 = new System.Windows.Forms.CheckBox();
  this.checkBox6 = new System.Windows.Forms.CheckBox();
  this.button1 = new System.Windows.Forms.Button();
  this.groupBox1.SuspendLayout();
  this.groupBox2.SuspendLayout();
  this.SuspendLayout();
  // 
  // groupBox1
  // 
  this.groupBox1.Controls.Add(this.checkBox3);
  this.groupBox1.Controls.Add(this.checkBox2);
  this.groupBox1.Controls.Add(this.checkBox1);
  this.groupBox1.Location = new System.Drawing.Point(12, 12);
  this.groupBox1.Name = "groupBox1";
  this.groupBox1.Size = new System.Drawing.Size(342, 89);
  this.groupBox1.TabIndex = 0;
  this.groupBox1.TabStop = false;
  this.groupBox1.Text = "片头";
  // 
  // groupBox2
  // 
  this.groupBox2.Controls.Add(this.checkBox6);
  this.groupBox2.Controls.Add(this.checkBox5);
  this.groupBox2.Controls.Add(this.checkBox4);
  this.groupBox2.Location = new System.Drawing.Point(12, 107);
  this.groupBox2.Name = "groupBox2";
  this.groupBox2.Size = new System.Drawing.Size(342, 102);
  this.groupBox2.TabIndex = 1;
  this.groupBox2.TabStop = false;
  this.groupBox2.Text = "片尾";
  // 
  // checkBox1
  // 
  this.checkBox1.AutoSize = true;
  this.checkBox1.ForeColor = System.Drawing.Color.Fuchsia;
  this.checkBox1.Location = new System.Drawing.Point(38, 21);
  this.checkBox1.Name = "checkBox1";
  this.checkBox1.Size = new System.Drawing.Size(72, 16);
  this.checkBox1.TabIndex = 0;
  this.checkBox1.Text = "60秒彩条";
  this.checkBox1.UseVisualStyleBackColor = true;
  // 
  // checkBox2
  // 
  this.checkBox2.AutoSize = true;
  this.checkBox2.ForeColor = System.Drawing.SystemColors.ControlText;
  this.checkBox2.Location = new System.Drawing.Point(38, 43);
  this.checkBox2.Name = "checkBox2";
  this.checkBox2.Size = new System.Drawing.Size(72, 16);
  this.checkBox2.TabIndex = 1;
  this.checkBox2.Text = "30秒黑场";
  this.checkBox2.UseVisualStyleBackColor = true;
  // 
  // checkBox3
  // 
  this.checkBox3.AutoSize = true;
  this.checkBox3.Location = new System.Drawing.Point(38, 65);
  this.checkBox3.Name = "checkBox3";
  this.checkBox3.Size = new System.Drawing.Size(72, 16);
  this.checkBox3.TabIndex = 2;
  this.checkBox3.Text = "20秒黑场";


  this.checkBox3.UseVisualStyleBackColor = true;
  // 
  // checkBox4
  // 
  this.checkBox4.AutoSize = true;
  this.checkBox4.Location = new System.Drawing.Point(38, 20);
  this.checkBox4.Name = "checkBox4";
  this.checkBox4.Size = new System.Drawing.Size(72, 16);
  this.checkBox4.TabIndex = 0;
  this.checkBox4.Text = "30秒黑场";
  this.checkBox4.UseVisualStyleBackColor = true;
  // 
  // checkBox5
  // 
  this.checkBox5.AutoSize = true;
  this.checkBox5.Location = new System.Drawing.Point(38, 42);
  this.checkBox5.Name = "checkBox5";
  this.checkBox5.Size = new System.Drawing.Size(72, 16);
  this.checkBox5.TabIndex = 1;
  this.checkBox5.Text = "15秒黑场";
  this.checkBox5.UseVisualStyleBackColor = true;
  // 
  // checkBox6
  // 
  this.checkBox6.AutoSize = true;
  this.checkBox6.Location = new System.Drawing.Point(38, 64);
  this.checkBox6.Name = "checkBox6";
  this.checkBox6.Size = new System.Drawing.Size(66, 16);
  this.checkBox6.TabIndex = 2;
  this.checkBox6.Text = "5秒黑场";
  this.checkBox6.UseVisualStyleBackColor = true;
  // 
  // button1
  // 
  this.button1.Location = new System.Drawing.Point(267, 244);
  this.button1.Name = "button1";
  this.button1.Size = new System.Drawing.Size(75, 23);
  this.button1.TabIndex = 2;
  this.button1.Text = "确定";
  this.button1.UseVisualStyleBackColor = true;
  this.button1.Click += new System.EventHandler(this.button1_Click);
  // 
  // TitlesCreditsControl
  // 
  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  this.ClientSize = new System.Drawing.Size(366, 282);
  this.Controls.Add(this.button1);
  this.Controls.Add(this.groupBox2);
  this.Controls.Add(this.groupBox1);
  this.Name = "TitlesCreditsControl";
  this.Text = "片头片尾彩条黑场添加";
  this.groupBox1.ResumeLayout(false);
  this.groupBox1.PerformLayout();
  this.groupBox2.ResumeLayout(false);
  this.groupBox2.PerformLayout();
  this.ResumeLayout(false);


  }


[解决办法]
你想干嘛?
是不是几个checkbox(复选框)只允许勾选一个?
可以改用radiobutton(单选)或者写事件来限制
[解决办法]
多选一就用radiobutton。
多选N就用checkbox。
如果是多选一或者多选0,那就要看怎么方便了,可以radiobutton加清除按钮,或者checkbox控制互斥。

如果你说没法做,那只能说明你的逻辑思维能力太差!
[解决办法]
这个不复杂啊,在CheckBox的Click事件里,如果Checked的值为true,就遍历同一个容器控件下的其它CheckBox,把它们的Checked属性设置为false就可以了啊。

C# code
checkbox1_Click(object sender, EventArgs e){  (CheckBox)cb  = (CheckBox)sender;  if (cb.Checked)  {    foreach (Control ctl in cb.GetContainerControl().Controls)    {       CheckBox cb1 = ctl as CheckBox;       if (cb1 != null && cb1 != cb) cb1.Checked = false;    }  }} 


[解决办法]

探讨
这个不复杂啊,在CheckBox的Click事件里,如果Checked的值为true,就遍历同一个容器控件下的其它CheckBox,把它们的Checked属性设置为false就可以了啊。


C# code


checkbox1_Click(object sender, EventArgs e)
{
(CheckBox)cb = (CheckBox)sender;
i……

热点排行