views:

138

answers:

3

I'm working on a .NET 2.0 WinForms app that uses MDI.

It works perfectly when I'm testing it under Windows 7, but when I install the exact same application in Windows XP the child windows are no longer MDI windows. I can drag them out of their parent window.

Does anybody have an explanation for this odd behavior?

Update: It works on Windows 7 and Vista. It works on XP when it is built on XP, but building the project and deploy it to XP then it doesn't work. This is getting stranger by the minute.

Code (I cut out the parts not dealing with the forms)

Imports Model = TakeHomeModel
Imports System.Windows.Forms

Public Class MainForm

Private WithEvents gebruikers As frmGebruikers
Private WithEvents fotos As frmFotos
Private WithEvents tweets As frmTweets
Private rapport As frmReport
Private zoeker As New frmZoek

Private Sub GebruikersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GebruikersToolStripMenuItem.Click
    If gebruikers.Visible = False Then
        gebruikers.Show()
    Else
        gebruikers.Hide()
    End If
End Sub

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Icon = My.Resources.appico
    Model.InitDatabase(My.Application.Info.DirectoryPath & "\takehome.accdb")
    gebruikers = New frmGebruikers
    fotos = New frmFotos
    tweets = New frmTweets
    rapport = New frmReport
    rapport.MdiParent = Me
    gebruikers.MdiParent = Me
    fotos.MdiParent = Me
    tweets.MdiParent = Me
    zoeker.MdiParent = Me
End Sub

Private Sub FotosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FotosToolStripMenuItem.Click
    If fotos.Visible = False Then
        fotos.Show()
    Else
        fotos.Hide()
    End If
End Sub

Private Sub TweetsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TweetsToolStripMenuItem.Click
    If tweets.Visible = False Then
        tweets.Show()
    Else
        tweets.Hide()
    End If
End Sub

End Class
A: 

One possibility would be if the child forms are loading before they are assigned the mdiparent property. This can happen anything inside the child form is referenced during the initialization process, either from outside or possible as a result as the "new" assignment.

xpda
I will try that, but why does it work in Windows 7 and not in XP?
Bloodsplatter
Ok, tried it, but you can't set the mdi parent in the designer.
Bloodsplatter
You're right -- I've edited the answer. One reason this might be the cause is that some controls have events that fire on initialization, and this behavior is not consistent between versions of Windows. Instead assigning the mdiparent in the loading of the main form, you might try assigning it in the loading of the child forms.
xpda
A: 

Ok, Update. I tried doing this through P/Invoke (get the hWnd of the MDICLIENT "window" and set that as parent (SetParentA)) and there was no difference (Still worked on Win7, not on XP). It seems as though XP just really doesn't like MDI.

Bloodsplatter
A: 

I have no problems using MDI children in Windows XP Windows Forms. We do it extensively.

I would imagine that you have something which is interfering with the way that MDI children are working on that PC.

I would try running on a different (clean install if possible), Windows XP machine to eliminate any issues related to graphics drivers, installation of third party tools which affect window layout etc.

Are you using standard Windows Forms or do you have a third party control being used which affects MDI? eg. Janus or Dev Express which convert MDI windows to tabs, for example?

James Berry
No 3rd party components, it's all vanilla .NET 2.0. And the XP install is very clean, it's my 7's Windows XP Mode. I had a friend test it on a clean install of XP in a VM without succes. I also tested the app on Vista and it worked just fine there.
Bloodsplatter