Hi,
Does C# (WinForms) support adding a view or control to another control? Could anyone give me an example? Thanks in advance.
I use this code in Objective-C.
[aView addSubview:anotherView];
Hi,
Does C# (WinForms) support adding a view or control to another control? Could anyone give me an example? Thanks in advance.
I use this code in Objective-C.
[aView addSubview:anotherView];
You can do this programatically with a Panel.
You could also use Visual Studio's Designer GUI to create a UserControl, which is more reusable, since you will be able to drag and drop it on to any form at design time.
Sorry if I misunderstand the question.
public Form1()
{
InitializeComponent();
Panel p = new Panel()
{
BackColor = Color.PowderBlue,
Location = new Point(10, 10)
};
p.Controls.Add(new Label()
{
Text = "Hello",
BackColor = Color.PaleGreen,
Location = new Point(20, 20)
});
p.Controls.Add(new Button()
{
Text = "Woof",
BackColor = Color.Orchid,
Location = new Point(60, 60)
});
this.Controls.Add(p);
}