John Terror
John Terror

Reputation: 41

How do I programmatically create a GUI and create it for my windows form?

As above, how do I create buttons or labels programmatically instead of using the drag and drop function?

Upvotes: 1

Views: 2547

Answers (2)

Thomas
Thomas

Reputation: 1126

The following sample is a code for creating a panel.

    public Panel createPanel()
    {
        Panel p = new Panel
        {
            BorderStyle = BorderStyle.FixedSingle,
            Size = new Size(506, 110),
            Name = "Panel"
        };

        Button button = new Button
        {
            Text = "Clear",
            Name = "Button",
            Location = new Point(410, 40)                
        };

        p.Controls.Add(button);
        return p;
    }

Upvotes: 2

Yochai Timmer
Yochai Timmer

Reputation: 49231

Go to YourForm.Designer.cs and see how it's done.

Remember that they're just object members.

Upvotes: 1

Related Questions