dotnet windows forms:
Hi Tiago M,
Although I don't quite understand why you would want to do this it should
work ok. I have used the following code to create a form within a panel (the
form contains a number of child controls that render correctly).
namespace FormInForm
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
FormEmbedded childForm = new FormEmbedded(); //Key line
childForm.TopLevel = false;
this.panelFormHolder.Controls.Add(childForm);
childForm.Show();
}
}
}
The one thing I did notice about your sample code was that you were creating
a form derived from the base class 'Form' and not from the actual form that
you want to display.
If the code line marked //Key line above is replaced with
Form childForm = new Form();
then child controls will not be rendered because the 'Form' base class does
not know about them.
Hope this helps.
wibberlet
Development blog at
http://wibberlet.blogspot.com =================================================
[quoted text, click to view] "Tiago M." wrote:
> Hi!
>
> I have a form inside a panel using:
>
> public void CreateNewFormInsidePanel(){
> Form form1 = new Form();
> form1.TopLevel = false;
> panel.Controls.Add(form1);
> form1.Show();
> form1.BringToFront();
> }
>
> Everything goes according plan when I'm creating a new form after a
> button click event but when I want to create a new form inside a panel
> just after initializing the main form it does not work.
>
> public Main2()
> {
> InitializeComponent();
> CreateNewFormInsidePanel();
>
> }
>
> The form appears inside the panel but without any label, combobox etc
> initialized.
>
> If I do a form1.show after the initialization the content of the form1
> appears but of course not inside the panel.
>
> Any help?