The following quick example should help.
public Form1()
{
InitializeComponent();
// create embedded form
var form = new Form();
form.SetBounds(100, 100, 200, 300);
form.BackColor = Color.PaleTurquoise; // set to highlight this form position
form.TopLevel = false; // important otherwise cannot add to Control collection
form.Visible = true; // important otherwise form does not show
form.FormBorderStyle = FormBorderStyle.None; // comment out to enable user to move form about
// add a button to the embedded form
var b1 = new Button();
b1.Location = new Point(20, 20);
b1.Text = @"Test button";
b1.Click += b1_Click;
form.Controls.Add(b1);
this.Controls.Add(form);
}
void b1_Click(object sender, EventArgs e) { MessageBox.Show(@"Test button pressed!"); }
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
Form1() is the constructor for my "MainForm" in my test program.
form is a newly created Form that I use as if it is a normal control.
The code is an example on how to use a form as a control on another form.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187