Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

18 Experts available now in Live!

Get 1:1 Help Now