Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On a WinForms form class, there is a bool type property named IsMDIContainer that indicate whether the form is a container for multiple-document interface (MDI) child forms. This property also can be changed in run-time, but there are no event raised when this property value is changed.

Is anyone knows how to detect that changes ? I have tried through WndProc on WM_STYLECHANGED message, but I have no result (exactly, I never receive this message through WndProc when I changed the value of the IsMDIContainer property). Thanks.
Posted
Comments
Vitaly Tomilov 30-Jun-12 22:01pm    
This property is virtual (implementation), and for that reason there is no event associated with its change. But why you want to catch this in the first place? Sounds unusual...
Sergey Alexandrovich Kryukov 30-Jun-12 23:31pm    
Exactly. I tried to explain it in my answer, with some detail and reasonable suggesting, please see...
--SA
Vitaly Tomilov 1-Jul-12 0:34am    
Good answer +5
Sergey Alexandrovich Kryukov 1-Jul-12 2:17am    
Thank you, Vitaly.
--SA
Sergey Alexandrovich Kryukov 30-Jun-12 23:16pm    
Why would you ever need it?!
--SA

1 solution

I don't think such event exists. If you want to find the style change in raw Windows API, you cal look at WS_* constants in Windows documentation. You will find only the extended style WS_EX_MDICHILD, but not a style associated with a MDI parent. As far as I remember the background, top-level window cannot be a MDI one (parent or child), instead, it has another window which take the whole area of the top-level window's client area. This is a special window called "MDI client"; and only the MDI client can be a parent of MDI children. Anyway, using P/Invoke is bad, because it breaks platform compatibility of your application.

Perhaps neither a Window message nor a .NET event you are hoping for is not found because nobody in clear memory and sober mind is not going to change this property value, forget about handling an event supposedly fired on this change. (By the way, as you want modify this property in your own code (only why?!), you could create your own event in your class derived from the Form.) Why?

I have a better idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. I can explain what to do instead.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can tell you what you could use instead.

Please see my past answers:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900