Solved

how can i add form to the Panel in C#.net window application??

Posted on 2011-03-09
4
681 Views
Last Modified: 2012-08-14
i want to know that how can i add form to the Panel in C#.net window application??

please refer the below code ...

MainPanel.Controls.Clear();
                    Admin objAdmin = new Admin();
                    objAdmin.TopLevel = false;
                    MainPanel.Controls.Add(objAdmin);

Open in new window


in above coding MainPanel is panel control and Admin is the form name , but how can i add form to the Panel control ??
0
Comment
Question by:Parth48
  • 2
4 Comments
 
LVL 7

Expert Comment

by:jdavistx
ID: 35083011
As far as I know, you cannot add a form to a panel, or any other container control besides an MdiContainer.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35085337
That will work...the key is setting TopLevel() to false as you've done.

You still need to Show() it though:

    objAdmin.Show();

Also, to make it appear seamless, set the FormBorderStyle() to None, and Dock() to Fill.
0
 

Author Comment

by:Parth48
ID: 35091690
please refer the below code ..

private void GetAdminForm()
        {
            //Add constuctor Logic here
            MainPanel.Controls.Clear();
            Form objform = this.FindForm();
            objform.MdiParent = this;
            objform.IsMdiContainer = true;
            Admin objAdmin = new Admin();
            ShowFormInControl(this.MainPanel, objAdmin);
        }

public static void ShowFormInControl(Control ctlContainer, Form frmEmbed)
        {
            frmEmbed.TopLevel = false;
            frmEmbed.FormBorderStyle = FormBorderStyle.None;
            frmEmbed.Dock = DockStyle.Fill;
            frmEmbed.Visible = true;
            ctlContainer.Controls.Add(frmEmbed);
        }

Open in new window


anything wrong in the above code ??
or i have to set mdi properties for the parent form and child form ??
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35091848
You're mixing two different styles of embedding forms...

An MDI approach is intended to have child forms within that can be moved around, minimized, maximized, etc...
*You can't be an MdiContainer and have an MdiParent so lines #6 and #7 are not supposed to be used together.
**Besides, line #6 is really trying to set the MdiParent to itself!

The TopLevel() false with no border and dock filled is really a way to use a form like a static control that fills an area.

Why do you keep using this construct in line #5?

            Form objform = this.FindForm();

The "this" already IS THE FORM ITSELF.  You don't need to "find" the form containing the form....?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 20
asp.net mvc5 6 17
VB.NET 2008 Winforms Signing 13 19
VS2013 publish C# application Created folder -- where is it??? 10 16
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question