private void InitializeMdiClient()
{
// If the mdiClient has previously been set, unwire events connected
// to the old MDI.
if (this.MdiClient != null)
{
this.MdiClient.HandleDestroyed -= this.MdiClientHandleDestroyed;
this.MdiClient.Layout -= this.MdiClientLayout;
}
if (this.ParentForm == null)
return;
// Get the MdiClient from the parent form.
foreach (Control control in this.ParentForm.Controls)
{
// If the form is an MDI container, it will contain an MdiClient control
// just as it would any other control.
this.m_mdiClient = control as MdiClient;
if (this.m_mdiClient == null)
continue;
// Assign the MdiClient Handle to the NativeWindow.
ReleaseHandle();
AssignHandle(this.MdiClient.Handle);
// Raise the HandleAssigned event.
this.OnHandleAssigned(EventArgs.Empty);
// Monitor the MdiClient for when its handle is destroyed.
this.MdiClient.HandleDestroyed += this.MdiClientHandleDestroyed;
this.MdiClient.Layout += this.MdiClientLayout;
break;
}
}