tags:

views:

78

answers:

2

I want to know the bounds of the grey scrollable area in an MDI parent -- the area in which MDI children are placed/arranged. I don't want it to include any menu, scroll bars, or status areas -- just the grey area.

this.mdiForm.ClientRectangle gives the whole interior of the Form, including scroll bars et al, which is not what I want.

A: 

The control is called MdiClient and it's automatically added when the IsMdiContainer property is set to true. You should be able to access it by doing:

// traditional way
MdiClient client = null;
foreach (Control c in this.mdiForm.Controls) {
    client = c as MdiClient;
    if (client != null) {
        break;
    }
}

// linq
MdiClient client = this.mdiForm.Controls
                       .OfType<MdiClient>()
                       .FirstOrDefault();
Josh Einstein
Thanks. That works fine too.
Grammarian
A: 

As always, just after posting, I figure it out.

Form has an internal property MdiClient. So, you can get the rectangle like this:

PropertyInfo pi = typeof(Form).GetProperty("MdiClient", 
    BindingFlags.Instance | BindingFlags.NonPublic);
MdiClient mdiClient = (MdiClient)pi.GetValue(this.form1, null);
Rectangle scrollableRect = mdiClient.ClientRectangle;

A production version would, of course, check for null in the appropriate places.

Grammarian