Solved

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

Posted on 2011-03-09
4
686 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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 86

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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