Windows form inside a Panel

344 views
Skip to first unread message

Savani Mahesh

unread,
Feb 23, 2009, 12:57:17 AM2/23/09
to DotNetDe...@googlegroups.com
Hi,

Visual Studio 2005, C# .Net 2.0. Window Forms Application.

I created a form with 2 panels. One panel containing 3 links to other 3 forms, second panel to hold the form. When user clicks on a link, I create instance of form, set its TopLevel property to false and add the form to second panel.

Problems I am facing are,
1) Form residing into the panel never get focus. So all shortcuts which works fine, when form is opened normally as a TopLevel control, do not work. The reason I guess is that "Form Into Panel" never gets windows messages, generated by OS central message loop, instead its parent form gets messages.

2) The form added to panel is floating. How to stop floating?

Please any one can help.

Regards,
Mahesh

Bhargav Patel

unread,
Feb 28, 2009, 11:41:29 AM2/28/09
to DotNetDe...@googlegroups.com
I CANT UNDERSTAND UR 1ST QUESTION , But If my understanding is good it
can be solved by opening secod form as dialog and dont use any form as
topmost.

for second problem u can just set forms borderstyle property NoBorder

CallMeLaNN

unread,
Mar 2, 2009, 7:26:34 AM3/2/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I am not sure about putting Form in Panel, sounds wired.
Try this
- Use MDI Form or (Can't be put in Panel)
- UserControl to put in the Panel.

From what I understood what is you trying to do, User Control is the
best. Otherwise, you can make popup Form by just show it "Form2.Show
(this);" or "Form2.ShowDialog(this);".

I am not sure the shortcuts can be functioning by this way or not.
However you can use custom code to listen to windows message that can
handle hotkey message, but it is difficult.

Hm...
Maybe you said floating because of you use Form2.Show() and the Form2
is not in Form1. It shoulb be like that. There is no way to put in
Panel, because it is Form. Instead, use User Control I mention above.
It is just like a Form but with no title bar. To do that:

1. Create User Control named UserControl1.
2. Place a control into it. E.g: drag Button, TextBox into the
UserControl1.
3. Rebuild the project. (Compulsory, otherwise UserControl1 is not in
your Toolbox)
4. The UserControl is placed in Toolbox, drag it into your main Form
or Panel in main Form. OR
5. Creat instance in code and add into Panel control. E.g:
Panel1.Control.Add(UserControl1)

Updating controls in User Control will also update where you place
it.
Reply all
Reply to author
Forward
0 new messages