Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with icon on creating new maximized MDI child form in .NET

I have a .NET 3.5 MDI WinForms application.

I set a a child form's Icon property, and the icon shows up correctly in the top left corner of the form. I then maximize the child form and the icon is still OK.

With the child form still maximized, I open another child window, which automatically comes up maximized. This form's icon is not the one in the Icon property, but the default .NET icon (the one with the blue, red, and yellow squares). However, if I resize the MDI parent form, the icon resets itself and displays properly.

Does anyone have a workaround or know why this happens?

like image 805
lc. Avatar asked May 20 '09 16:05

lc.


People also ask

Which control is support to MDI form?

Forms namespace supports multiple document interface (MDI) applications, and the MenuStrip control supports menu merging. MDI forms can also ToolStrip controls.


3 Answers

A slight modification to Calanus' solution:

    private void MdiBase_Load(object sender, EventArgs e)
    {
        // Fixes bug where loading form maximised in MDI window shows incorrect icon.
        this.Icon = Icon.Clone() as Icon;
    }

This allows you to set the icon at design time (just as you would for other forms), and does not need any hard-coded file or resource accessing.

like image 162
Tom Avatar answered Sep 23 '22 00:09

Tom


Right I have found a solution...

The workaround for this is to set the icon again on the load event of the child form as follows:

private void StatsForm_Load(object sender, EventArgs e)
{
    //bug that means you have to set the desired icon again otherwise it reverts to default when child form is maximised
    Icon = new System.Drawing.Icon("research.ico");
}

This does mean that you will have to first add the icon file in question into your VS project/solution and set it to "Copy Always" so that is copied when your solution is built.

HTH Calanus

like image 23
Calanus Avatar answered Sep 21 '22 00:09

Calanus


I found that the only solution was to deactivate and then reactivate the MDI child:

document.Show();
// Work-around for error in WinForms that causes MDI children to be loaded with the default .NET icon when opened maximised.
ActivateMdiChild(null);
ActivateMdiChild(document);

This is the solution given in this reply on MSDN forums and it worked for me.

like image 22
open-collar Avatar answered Sep 20 '22 00:09

open-collar