PC Review


Reply
Thread Tools Rate Thread

Embedding a Form in a Panel

 
 
kevin
Guest
Posts: n/a
 
      7th Aug 2003
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.

 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      8th Aug 2003
Kevin
This might help

http://msdn.microsoft.com/library/de...asp?frame=true

Stephen


"kevin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
 
kevin
Guest
Posts: n/a
 
      8th Aug 2003
How does the article "Not Your Father's Data Binding" answer my
question? I don't see anything in there about embedding a form in a panel.

Thanks,
Kevin.

Stephen Muecke wrote:
> Kevin
> This might help
>
> http://msdn.microsoft.com/library/de...asp?frame=true
>
> Stephen


 
Reply With Quote
 
kevin
Guest
Posts: n/a
 
      8th Aug 2003
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.

 
Reply With Quote
 
kevin
Guest
Posts: n/a
 
      8th Aug 2003
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.

 
Reply With Quote
 
kevin
Guest
Posts: n/a
 
      8th Aug 2003
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...

 
Reply With Quote
 
AlexS
Guest
Posts: n/a
 
      8th Aug 2003
You might need to add also form to Controls collection of the panel.

Good point on TopLevel!

HTH
Alex

"kevin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Joe White
Guest
Posts: n/a
 
      9th Aug 2003
> 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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedding a form into a panel control =?Utf-8?B?Q2V6YXI=?= Microsoft Dot NET Framework Forms 1 22nd Apr 2005 10:34 PM
Embedding an application within a Panel... PL Microsoft C# .NET 0 6th Aug 2004 08:32 PM
Embedding form in a panel to allow form in non-child window area Yasutaka Ito Microsoft Dot NET Framework Forms 2 4th Feb 2004 05:58 PM
Embedding form in a panel to allow form in non-child window area Yasutaka Ito Microsoft Dot NET 1 4th Feb 2004 05:58 PM
Form inside a panel...Panel doesn't show the scrollbars correctly? Özden Irmak Microsoft Dot NET Framework Forms 0 14th Oct 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 PM.