Inside an MDI form is a client area that hosts the mdi child forms. How do I find out how big that area is? The best I can come up with so far is finding the total size of the parent's potential client area (mdiparent.ClientRectangle) and then subtracting off the sizes of components like toolbars, etc that take away from the client area. Is there a better way?
Asked
Active
Viewed 1.1k times
2 Answers
23
There is no property on a form that gives you access to the MDI client window. But you can find it back like this:
public MdiClient GetMdiClientWindow() {
foreach (Control ctl in this.Controls) {
if (ctl is MdiClient) return ctl as MdiClient;
}
return null;
}
From there, just use its Size property.

Hans Passant
- 922,412
- 146
- 1,693
- 2,536
-
1Thanks, that worked awesome. For some reason I had to subtract an additional 4 pixels (probably for a frame border?), but I can live with that. – Jeff Mar 03 '09 at 03:16
-
4@Jeff Use MdiClient.ClientSize instead of subtracting 4 pixels – Kishore A Jul 19 '12 at 23:37
-
Using LINQ: `this.Controls.OfType
().FirstOrDefault();` – rucamzu Apr 20 '18 at 13:35
1
Here's a variant of that code in vb.net:
Public Function GetMdiClientWindowSize() As Size
For Each ctl As Control In Me.MdiParent.Controls
If TypeOf ctl Is MdiClient Then
Return ctl.Size
End If
Next
Return Nothing
End Function

Jeff
- 8,020
- 34
- 99
- 157