Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / C#
Tip/Trick

MDI Parent Menu Client Maximized Icon Fix (workaround)

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
14 Sep 2011CPOL 22.7K   1   4
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:
C#
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;
                }
            }
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Denmark Denmark

Comments and Discussions

 
QuestionThanks Pin
naraayanan29-Sep-13 21:47
naraayanan29-Sep-13 21:47 
AnswerRe: Thanks Pin
Paw Jershauge30-Sep-13 8:21
Paw Jershauge30-Sep-13 8:21 
GeneralThanks Paw, I've experienced the same bug, I'd assume lots o... Pin
AndrewHeard19-Sep-11 22:36
AndrewHeard19-Sep-11 22:36 
GeneralRe: your welcome ;) Pin
Paw Jershauge21-Sep-11 20:39
Paw Jershauge21-Sep-11 20:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.