mardi 1 novembre 2016

Add a checkbox control to a group box control pragmatically using C#

I'm working on a project at work. I've never added controls at run time. I created a check box with the following code.

this.chkRelatedChangeSets.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.chkRelatedChangeSets.Enabled = false;
            this.chkRelatedChangeSets.Location = new System.Drawing.Point(300, 460);
            this.chkRelatedChangeSets.Name = "chkRelatedChangSets";
            this.chkRelatedChangeSets.Size = new System.Drawing.Size(150, 23);
            this.chkRelatedChangeSets.AutoSize = true;
            this.chkRelatedChangeSets.Text = "Retrieve related Workitem changsets"

And then the previous engineer had created the following group box. I added my check box using the groupbox.control.add method

this.grpChangesets.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left)));
            this.grpChangesets.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.grpChangesets.Controls.Add(this.lvwChangesets);
            this.grpChangesets.Controls.Add(this.cB_Copy_Files_for_Sandcastle);
            this.grpChangesets.Controls.Add(this.chkRelatedChangeSets);
            this.grpChangesets.Location = new System.Drawing.Point(10, 286);
            this.grpChangesets.Name = "grpChangesets";
            this.grpChangesets.Size = new System.Drawing.Size(365, 200);
            this.grpChangesets.TabIndex = 31;
            this.grpChangesets.TabStop = false;
            this.grpChangesets.Text = "Changesets";

However, when I run the app the checkbox appears behind the groupbox. I've included a picture below. How can I correct this?

enter image description here




Aucun commentaire:

Enregistrer un commentaire