Solved

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

Posted on 2011-03-09
4
679 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now