?
Solved

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

Posted on 2011-03-09
4
Medium Priority
?
687 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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: …

718 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