MDI Child Icon Bug

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
I find that the icon of a maximised MDI child form does not show correctly until the MDI form is resized. Instead you get the standard icon with a red, blue and yellow box showing. Only when the MDI form is resized is this refreshed. This problem occurs whether the icon is set at design time or on loading the child form. The best solution I can come up with is the truly awful:

Code:
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MDIParent1.Width = MDIParent1.Width + 1
        MDIParent1.Width = MDIParent1.Width - 1
        Timer1.Enabled = False
    End Sub
Any better ideas?
 
Hi,

What version of Visual Studio are using?

What are the steps you follow to add an icon to your form? Do you use code, the form designer or the App.ico? Give us a little more information about how to recreate your problem.

Thanks,
kmg
 
Visual Studio Express 2005. If you have this then I'm sure you can replicate the problem by adding an MDI form through the Project/Add Windows Form menu and setting an icon in the child form at design time. I'm not using the AppIcon as I want that to be different.

As I say, it happens whether I set the icon in the form designer or in code. As you'll know, the icon appears in the MDI form menu strip when the child form is maximised. Since making the original post I've discovered that you can solve the problem by making this menu strip invisible and then visible again after loading the form, so slightly better than my first solution but still not very good.
 
This works OK:

Code:
 Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripButton.Click

        Dim q As New Form1

        q.WindowState = FormWindowState.Maximized
      
        q.MdiParent = Me
       
        q.Show()
       
        If TypeName(Me.MenuStrip.Items(0)) = "SystemMenuItem" Then
             Dim t As Long
             t = Me.MenuStrip.Height
            Me.MenuStrip.Items(0).Image = q.Icon.ToBitmap
            Me.MenuStrip.Height = t    'otherwise it goes too big.
        Else
            Debug.Print("SystemMenuItem not found.")
        End If

    End Sub
 
Back
Top