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

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
cycledudeAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
cycledudeAuthor Commented:
Hi

I am referencing the forms from a class, so 'this' is referencing the class and not the mdiform.
0
 
cycledudeAuthor Commented:
top man ;o)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.