Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding a winform within a winform (c#)

Tags:

c#

winforms

Is it possible to embed a windows form within another windows form?

I have created a windows form in Visual Studio along with all its associated behaviour.

I now want to create another windows form containing a tab view, and I want to embed the first windows form into the tab view. Is this possible?

like image 790
phrenetic Avatar asked Nov 19 '08 11:11

phrenetic


People also ask

Is WinForm deprecated?

Win Form has been used to develop many applications. Because of its high age (born in 2003), WinForm was officially declared dead by Microsoft in 2014. However, Win Form is still alive and well.

How do I hide a form in WinForm?

If you Don't want the user to be able to see the app at all set this: this. ShowInTaskbar = false; Then they won't be able to see the form in the task bar and it will be invisible.


1 Answers

Disclaimer

This will work as I am using it in my application extensively. That being said I would pursue the User Control route as depending on how far you carry the embedding things start to flake out. FYI


Yes this is possible. This is how:

public static void ShowFormInContainerControl(Control ctl, Form frm)
{
    frm.TopLevel = false;
    frm.FormBorderStyle = FormBorderStyle.None;
    frm.Dock = DockStyle.Fill;
    frm.Visible = true;
    ctl.Controls.Add(frm);
}

I have that in a Class Library and then I call it like so from the FORM I want to embed.

public FrmCaseNotes FrmCaseNotes;
FrmCaseNotes = new FrmCaseNotes();
WinFormCustomHandling.ShowFormInContainerControl(tpgCaseNotes, FrmCaseNotes);

Where tpgCaseNotes is the control I want Form FrmCaseNotes embedded in.
In this case a tab page on the Form I am calling from.

like image 67
Refracted Paladin Avatar answered Sep 20 '22 15:09

Refracted Paladin