MDI Parent Menu Client Maximized Icon Fix (workaround)






4.67/5 (3 votes)
Ever noticed that the icon of a child form inside a MDI Parent, is not correctly displayed in the parent main menu strip, if the state of the child form is set to maximized before its shown.
Put this code into the MDI Parent form to fix that issue:
protected override void OnMdiChildActivate(EventArgs e)
{
base.OnMdiChildActivate(e);
if (ActiveMdiChild != null && ActiveMdiChild.WindowState == FormWindowState.Maximized && this.MainMenuStrip != null && this.MainMenuStrip.Items.Count > 0)
{
if (ActiveMdiChild.Icon != null)
{
Bitmap bmp = new Bitmap(16, 16);
bmp.MakeTransparent();
using (Graphics gp = Graphics.FromImage(bmp))
gp.DrawIcon(ActiveMdiChild.Icon, new Rectangle(0, 0, 16, 16));
this.MainMenuStrip.Items[0].Image = bmp;
}
}
}