2017-11-10 16 views
0

に応答していない、私が編集し、テキストボックスに書くことができますが、私はチェックボックスがここ に応答していないコードです:C#のチェックボックスが、私はチェックボックスの3列と2 RichTextBoxesを含むTableLayoutPanelを拡張するクラスを作成しTableLayoutPanel

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); } 

その後、実行時にStepPanelを別のパネルに追加します。 チェックボックスをクリックしたときの状態は変わりません。何が間違っていますか?

答えて

0

次のコードはSee Gif Hereで動作します。なぜあなたはチェックボックスでラベルを開始しようとしていますか?パネル

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
     var uc = new UserControl1(); 
     panel1.Controls.Add(uc); 
    } 
} 

UserControl1の部分クラスにコントロールを追加します

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); 
    } 
} 

フォームが

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; 
} 
+0

あなたは私のUserControl1クラスの他の部分クラスを示してもいいですか?私のケースでは、StepPanelクラスでInitializeComponent()を呼び出すことができないので、もしあれば、 – ASayed

+0

私はあなたのコードを渡って来た唯一の問題は、あなたがチェックボックスでラベルを開始しようとしているということです。それがちょうど悪い命名なら、おそらくすべてのファイルを閉じて、プロジェクトを再構築してみてください。ビルド – DuckSoy

+0

と呼ばれる上部のツールバーでこれを見つけることができます。program.cs以外のコードはすべて – DuckSoy

関連する問題