[英]c# CheckBox is not responding in TableLayoutPanel
I created a class extending TableLayoutPanel containing 3 columns of a CheckBox and two RichTextBoxes , I can edit and write in the textboxes but I CheckBox is not responding here's the code : 我创建了一个扩展TableLayoutPanel的类,该类包含一个CheckBox的3列和两个RichTextBoxes,我可以在文本框中进行编辑和编写,但是我CheckBox没有响应,这里的代码是:
public class StepPanel : TableLayoutPanel
{
public RichTextBox result;
public CheckBox checkBox;
public RichTextBox step;
public StepPanel()
{
this.result = new RichTextBox();
this.label = new CheckBox();
this.step = new RichTextBox();
this.ColumnCount = 3;
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.Controls.Add(this.checkBox, 0, 0);
this.Controls.Add(this.step, 1, 0);
this.Controls.Add(this.result, 2, 0); }
I then add some StepPanel's to another panel in runtime the checkbox does not change it's state when I click on it , what is wrong there ? 然后,我在运行时将一些StepPanel添加到另一个面板中,当我单击该复选框时,该复选框不会更改其状态,这是怎么回事?
The following code works See Gif Here . 以下代码有效, 请参见Gif Here 。 why are you trying initiate a label with a checkbox?
为什么要尝试使用复选框启动标签?
public partial class UserControl1 : TableLayoutPanel
{
public RichTextBox res;
public CheckBox checkBox;
public RichTextBox steps;
public UserControl1()
{
InitializeComponent();
res = new RichTextBox();
checkBox = new CheckBox();
steps = new RichTextBox();
this.ColumnCount = 3;
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.Controls.Add(this.checkBox, 0, 0);
this.Controls.Add(this.steps, 1, 0);
this.Controls.Add(this.res, 2, 0);
}
}
Form that adds control to panel 向面板添加控件的表单
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var uc = new UserControl1();
panel1.Controls.Add(uc);
}
}
UserControl1 partial Class UserControl1局部类
partial class UserControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.SuspendLayout();
//
// label
//
this.label.AutoSize = true;
this.label.Location = new System.Drawing.Point(81, 74);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(35, 13);
this.label.TabIndex = 0;
this.label.Text = "label1";
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(84, 141);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(200, 100);
this.tableLayoutPanel1.TabIndex = 1;
//
// UserControl1
//
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.label);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(602, 329);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label;
private System.Windows.Forms.RichTextBox result;
private System.Windows.Forms.RichTextBox step;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.