Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
how i draw a line on MDIParents??????
Posted
Comments
BillWoodruff 28-Dec-13 16:59pm    
The same ways that were suggested to you in answers to your previous question. An MdiParent is ... a Form.
Sergey Alexandrovich Kryukov 28-Dec-13 18:27pm    
No, Bill, I'm afraid you miss the point. This is not a re-post.

Try to do it by yourself. When a form becomes an MDI parent (not child!), it makes it hard to deal with it. I don't think your correct advice you gave OP in your answer to his past question will work. Please see my answer.

—SA
BillWoodruff 5-Jan-14 3:32am    
Good catch, Sergey !

Thanks to Sergey for reminding me of the special nature of the MDIParentForm !

Once you have a valid reference to the MdiClient Form ... which is not visible at design-time ... as shown in this (Jan. 3, 2014) QA answer: [^]:

1. You can draw lines on it using the Paint EventHandler, as shown by OriginalGriff's code: [^].

2. or, set its BackgroundImage, as I suggested in: [^].

The MdiClient is a Form, and no special API calls are needed to use its Paint Event, or set its BackgroundImage.

However, please keep in mind the cautions I stated in the cited answer to the question on defining a Click EventHandler for an MdiParent Form: that using the MdiClient is a kind of hack. I would avoid using it unless absolutely necessary.
 
Share this answer
 
Comments
TnTinMn 5-Jan-14 10:05am    
I think your method to get the MDIClient control could be dehackified (hey, a new word :)) if you iterated the form's control collection like shown here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.ismdicontainer%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
versus relying on the control to be the last control in the collection.

Perhaps Something like this:
private MdiClient GetMDIClientControl(Form frm)
{
MdiClient ret = null;
if (frm.IsMdiContainer)
{
foreach (Control c in frm.Controls)
{
if (c is System.Windows.Forms.MdiClient)
{
ret = (MdiClient)c;
break;
}
}
}
return ret;
}
This is possible but quite difficult. Moreover, I'm pretty much sure: this is impossible to do by using pure System.Windows.Forms; you would need to use P/Invoke (which will greatly compromise the platform compatibility of your code).

Some background: behind the scene (and behind the capabilities of .NET FCL), there is an intermediate window which works with MDI children. This window is a child of the MDI parent, is called "MDI client" and its handle is not exposed to a .NET user. You would need to access this window using raw Windows API, turn it a reference to a form using the Form wrapper and manipulate it (or manipulate it using raw Windows API directly).

I seriously advise you to abandon this counter-productive and fruitless idea. It will take your time and will give you quite ugly results. Why bothering? Here is the 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. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 
Comments
BillWoodruff 5-Jan-14 3:43am    
Good catch, Sergey, thanks !

fyi: no API calls are necessary to use the MdiClient Paint Event, or set its BackgroundImage: see response below.
Sergey Alexandrovich Kryukov 5-Jan-14 3:49am    
Probably you are right, if you work with MdiClient class. Where is that "response below"? Maybe I missed something. Do you know how to get he instance of MdiClient? I never tried that...
—SA
BillWoodruff 5-Jan-14 9:03am    
The link in the response is valid:

http://www.codeproject.com/Answers/705138/MDI-form-click-event

I can think of a better way to get at it, however, and if I have time, I'll revise that code.

cheers, Bill
Sergey Alexandrovich Kryukov 5-Jan-14 9:11am    
I up-voted that answer, but please see my comment. I never tried it, and only recently found MdiClient class, and still don't no a "legitimate" way of getting its instance. My 5 was more to appreciate the sophistication you got into, but it does not look reasonable to me, even if you successfully tested the approach.

This is yet another reason to never using MDI. It looks like Microsoft not only trying to phase it out (for good reason), but also neglects it. I used to get MDI client handle in native code, using Windows API, which is also not fun, but that way is
legitimate...

—SA

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