Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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!
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

824 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