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

x
?
Solved

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

Posted on 2014-02-21
5
Medium Priority
?
778 Views
Last Modified: 2014-02-21
Hi

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
0
Comment
Question by:cycledude
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
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
0
 

Author Comment

by:cycledude
ID: 39876145
Hi

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

Accepted Solution

by:
AndyAinscow earned 2000 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;
                    break;
                }
            }
//x is the MDIParent (main window of the application)
0
 

Author Closing Comment

by:cycledude
ID: 39876240
top man ;o)
0
 
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;
                    break;
                }
            }

Open in new window

0

Featured Post

Independent Software Vendors: 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Integration Management Part 2
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. …

885 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