Reputation: 41
As above, how do I create buttons or labels programmatically instead of using the drag and drop function?
Upvotes: 1
Views: 2547
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
Reputation: 49231
Go to YourForm.Designer.cs
and see how it's done.
Remember that they're just object members.
Upvotes: 1