Search code examples
visual-studioconstructorgroupbox

Way to create a Group box constructor Visual Studio? (Rookie question)


I created a group box with everything I want in place (see image) - Now is there a way(I.E. - menu option) to create a constructor for this? Looking for something similar to this(https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.groupbox.-ctor?view=netframework-4.7.2). The only difference is that I pre made my group box so that I could visualize it, now I need a constructor for it so that I can create it into an array. I hope this makes sense to you guys - I am new to Visual Studios(Dumbed down answers are appreciated). Thank you.

enter image description here


Solution

  • If you look at the Designer file for your form (it's listed in the Solution Explorer window), you will see the code-generated for your groupbox, and any other controls on the form. It will look something like this:

    private void InitializeComponent()
    {
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.SuspendLayout();
        // 
        // groupBox1
        // 
        this.groupBox1.Location = new System.Drawing.Point(76, 28);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(200, 100);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "groupBox1";
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 261);
        this.Controls.Add(this.groupBox1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);
    
    }