Solved

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

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

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
Sort GridView by ID Descending 1 24
How to read text with RegEx... 2 33
Problem to Office 1 39
C# DataTable (in memory) vs SQL Lookups 4 30
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

680 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