Solved

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

Posted on 2014-02-21
5
720 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 44

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 44

Accepted Solution

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

Author Closing Comment

by:cycledude
ID: 39876240
top man ;o)
0
 
LVL 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
Runtime Exceptions when trying to submit data 28 36
Host asp.net pages 5 25
Replace &lt; with < 14 53
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

10 Experts available now in Live!

Get 1:1 Help Now