C#2010 winforms referencing the mdi parent form from a class

Posted on 2014-02-21
Last Modified: 2014-02-21

I have an application in which there is an mdiparent and lost of child forms.

I am trying to get a custom message form to appear in the parent from a class.. just to say 'please wait for process to complete'

so I created the form, and a reference to it:

form msg = new frmMessages()

now i need to tell the form that the mdiform is the parent, then display it .... this is where I am stuck
Question by:cycledude
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
  • 2
LVL 44

Expert Comment

ID: 39876132
You should set this property when you create the child form:
childForm.MdiParent = this;
so the this.MdiParent in your child should give you what you want

Author Comment

ID: 39876145

I am referencing the forms from a class, so 'this' is referencing the class and not the mdiform.
LVL 44

Accepted Solution

AndyAinscow earned 500 total points
ID: 39876199
OK, how about this then:
            Form x = null;
            foreach (Form f in Application.OpenForms)
                if (f.Text == "MDIParent1")  //REPLACE WITH THE TEXT OF THE MAIN WINDOW
                    x = f;
//x is the MDIParent (main window of the application)

Author Closing Comment

ID: 39876240
top man ;o)
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39876740
You could also check the IsMdiContainer() property:
            foreach(Form frm in Application.OpenForms)
                if (frm.IsMdiContainer)
                    Form msg = new frmMessages();
                    msg.MdiParent = frm;

Open in new window


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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 43
Dictionary and array of [N] size - performance tuned 12 52
Create a Dropdown list with sub group 10 43
Pdf not loading 2 40
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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