Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2007

Tip: Looking for answers? Try searching our database.

Form inside a panel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tiago M. - 30 Mar 2007 13:10 GMT
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?
Wibberlet - 30 Mar 2007 19:14 GMT
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

=================================================

> Hi!
>
[quoted text clipped - 26 lines]
>
> Any help?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.