Embedding a Form in a Panel

Discussion in 'Microsoft Dot NET Framework Forms' started by kevin, Aug 7, 2003.

  1. kevin

    kevin Guest

    Hi,

    I've done this kind of thing in Win32 using Delphi so I would imagine
    there must be an equivalent in WinForms...

    How do I embed a form in a panel? This is the most convenient way to
    implement an SDI style application (like Outlook) that I know of. Some
    hacks that I've seen involve creating an MDI container and creating MDI
    child forms that don't have minimize or maximize buttons. If this is
    the only solution I'll accept it but I haven't managed to get it to work
    properly in .NET either. However, I'd rather not do this - the
    embedding would be the best solution.

    I would like to be able to replace the embedded form dynamically and I
    don't want to have to create user controls to do this. I want to be
    able to treat the forms as regular forms in the IDE so that I have the
    option of displaying them outside the main window frame as well.

    Thanks,
    Kevin.
     
    kevin, Aug 7, 2003
    #1
    1. Advertisements

  2. Kevin
    This might help

    http://msdn.microsoft.com/library/d...us/dnadvnet/html/vbnet02122002.asp?frame=true

    Stephen


    "kevin" <> wrote in message
    news:...
    > Hi,
    >
    > I've done this kind of thing in Win32 using Delphi so I would imagine
    > there must be an equivalent in WinForms...
    >
    > How do I embed a form in a panel? This is the most convenient way to
    > implement an SDI style application (like Outlook) that I know of. Some
    > hacks that I've seen involve creating an MDI container and creating MDI
    > child forms that don't have minimize or maximize buttons. If this is
    > the only solution I'll accept it but I haven't managed to get it to work
    > properly in .NET either. However, I'd rather not do this - the
    > embedding would be the best solution.
    >
    > I would like to be able to replace the embedded form dynamically and I
    > don't want to have to create user controls to do this. I want to be
    > able to treat the forms as regular forms in the IDE so that I have the
    > option of displaying them outside the main window frame as well.
    >
    > Thanks,
    > Kevin.
    >
     
    Stephen Muecke, Aug 8, 2003
    #2
    1. Advertisements

  3. kevin

    kevin Guest

    kevin, Aug 8, 2003
    #3
  4. kevin

    kevin Guest

    Joe White wrote:
    > Even in Delphi, you're better off using TFrames for this, rather than
    > TForms. If you need to display a TFrame free-floating, then just create
    > a new instance of TForm and parent the frame to it. I do this quite
    > often at work.


    OK, but that's because Delphi has TFrames. .NET doesn't have anything
    like that. UserControls are not quite like TFrames unfortunately.
    TFrames are much easier to work with!! This is one of the features that
    gives Delphi an edge still.

    > So, I would recommend that you use UserControls instead of Forms.


    Are you talking about dynamically creating and destroying UserControls?
    So I would create a UserControl for each "form" I wanted to display?

    > If you're dead-set on using Forms, though, then when using them as
    > children, you should set their FormBorderStyle to None before setting
    > their Parent (thus, effectively, turning them into UserControls!).


    I'll try to see if this works.

    Thanks,
    Kevin.
     
    kevin, Aug 8, 2003
    #4
  5. kevin

    kevin Guest

    kevin wrote:
    >> If you're dead-set on using Forms, though, then when using them as
    >> children, you should set their FormBorderStyle to None before setting
    >> their Parent (thus, effectively, turning them into UserControls!).

    >
    > I'll try to see if this works.


    Thanks for your help! It worked and the full code that was required was:

    WinForm1 embeddedForm = new WinForm1();
    embeddedForm.TopLevel = false;
    embeddedForm.FormBorderStyle = FormBorderStyle.None;
    embeddedForm.Parent = this.panel1;
    embeddedForm.Show();

    Until I added the TopLevel = false it was raising an ArgumentException.

    Thanks,
    Kevin.
     
    kevin, Aug 8, 2003
    #5
  6. kevin

    kevin Guest

    AlexS wrote:
    > You might need to add also form to Controls collection of the panel.


    If the reason for this is that it will be "cleaned up" (disposed?)
    automatically then there is no need. I'll be managing that through
    other code because I'll be switching between one form and another
    dynamically. Is there another reason why I'd need to add it to the
    Controls collection? It seems to work fine as it is right now...
     
    kevin, Aug 8, 2003
    #6
  7. kevin

    AlexS Guest

    You might need to add also form to Controls collection of the panel.

    Good point on TopLevel!

    HTH
    Alex

    "kevin" <> wrote in message
    news:...
    > kevin wrote:
    > >> If you're dead-set on using Forms, though, then when using them as
    > >> children, you should set their FormBorderStyle to None before setting
    > >> their Parent (thus, effectively, turning them into UserControls!).

    > >
    > > I'll try to see if this works.

    >
    > Thanks for your help! It worked and the full code that was required was:
    >
    > WinForm1 embeddedForm = new WinForm1();
    > embeddedForm.TopLevel = false;
    > embeddedForm.FormBorderStyle = FormBorderStyle.None;
    > embeddedForm.Parent = this.panel1;
    > embeddedForm.Show();
    >
    > Until I added the TopLevel = false it was raising an ArgumentException.
    >
    > Thanks,
    > Kevin.
    >
     
    AlexS, Aug 8, 2003
    #7
  8. kevin

    Joe White Guest

    > OK, but that's because Delphi has TFrames. .NET doesn't have anything
    > like that. UserControls are not quite like TFrames unfortunately.
    > TFrames are much easier to work with!! This is one of the features that
    > gives Delphi an edge still.


    Really? As far as I've seen, UserControls are pretty much the
    equivalent of TFrames. What are some specific downsides to UserControls
    that you're running into?


    >> So, I would recommend that you use UserControls instead of Forms.

    >
    > Are you talking about dynamically creating and destroying UserControls?
    > So I would create a UserControl for each "form" I wanted to display?


    Right. Instead of creating multiple forms (one for each page you want
    to be able to show in your master window), you would create the same
    number of UserControls. (Just like you would create that number of
    TFrames in Delphi. The app I'm doing for work is built this way,
    swapping different TFrames in and out of the same master window.)
     
    Joe White, Aug 9, 2003
    #8
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Cooper

    Re: Embedding Office App in a form

    Ian Cooper, Jul 3, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    470
    Guest
    Jul 4, 2003
  2. Özden Irmak

    Form inside a panel...Panel doesn't show the scrollbars correctly?

    Özden Irmak, Oct 14, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    520
    Özden Irmak
    Oct 14, 2003
  3. Yasutaka Ito

    Embedding form in a panel to allow form in non-child window area

    Yasutaka Ito, Feb 4, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    402
    Yasutaka Ito
    Feb 4, 2004
  4. Guest

    Embedding a form into a panel control

    Guest, Apr 22, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    204
    Guest
    Apr 22, 2005
  5. SammyBar

    Embedding IE inside a windows form, is it any sample code?

    SammyBar, Aug 16, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    200
    Nicholas Paldino [.NET/C# MVP]
    Aug 16, 2005
Loading...

Share This Page