A set of .NET Framework managed libraries for developing graphical user interfaces.
Hi @Rahul Kumar , Welcome to Microsoft Q&A.
You need to set the location manually.
You also need to set the anchor attribute.
private void Form1_Load(object sender, EventArgs e)
{
Form2 hm = new Form2();
hm.TopLevel = false;
hm.FormBorderStyle = FormBorderStyle.None;
hm.StartPosition = FormStartPosition.Manual; // Set the start position to Manual
hm.Location = new Point((panel1.Width - hm.Width) / 2, (panel1.Height - hm.Height) / 2); // Calculate the center position
hm.Anchor = AnchorStyles.None; // Set the Anchor property to None
panel1.Controls.Add(hm);
hm.BringToFront();
hm.Show();
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.