-
Jul 19th, 2024, 04:21 PM
#1
[RESOLVED] MDI Children Not Respecting Order
I have a class defined as a readonly property in a form that is an MDI child.
What I do when an event is fired is:
- Loop over the MDI children
- If the respective class' IsHidden is false then call Show
- Loop over the MDI children again ordered by their respective class' SortOrder
- Call BringToFront to set their order
The reason this is relevant is because if one of the MDI children become maximized, the others are hidden. So the event getting fired is when the maximized child is going back to its normal size and I need to reshow the MDI children that were previously hidden.
Here is the business logic described above:
Code:
Dim formEnteringFullScreen = DirectCast(sender, FormCamera)
Dim cameraWindows = FlowLayoutPanelCameras.Controls.OfType(Of FormCamera)
For Each cameraWindow In cameraWindows
If (cameraWindow Is formEnteringFullScreen) Then
Continue For
End If
If (Not cameraWindow.Camera.IsHidden) Then
cameraWindow.Show()
End If
Next
For Each cameraWindow In cameraWindows.OrderBy(Function(window) window.Camera.SortOrder)
cameraWindow.BringToFront()
Next
The issue is that it doesn't seem like the BringToFront is actually setting the Z-Index properly because if I two children forms, maximize the second, then make it go back to its normal size, the second one now shows up as the first one.
What I expect to happen is that after every form has been shown, calling BringToFront would change the Z-Index so that the order is what it was prior to the child MDI form being the only one shown.
-
Jul 19th, 2024, 11:57 PM
#2
Re: MDI Children Not Respecting Order
Are the SortOrder values what you expect, i.e. is BringToFront being called in the order you expect but not producing the z-order you expect?
-
Jul 20th, 2024, 12:50 PM
#3
Re: MDI Children Not Respecting Order
Correct. If I setup a breakpoint on where I'm calling BringToFront, it always executes in the same order. For example:
- I open the second form in full screen, which hides all the rest
- I click close to trigger the code in post #1
- The first form breaks first
- The second form breaks second
- The second form shows up first and the first form shows up second
- I click on the second form (which was originally the first form), which hides all the rest
- I click close to trigger the code in post #1
- The first form breaks first
- The second form breaks second
- The second form (which was originally the first form) shows up first and the first form (which was originally the second form) shows up second
So it doesn't really make sense to me because it appears as though the z-order is completely ignored when calling BringToFront.
Update - Even doing this produces the same results:
Code:
Dim orderedCameras = cameraWindows.OrderBy(Function(window) window.Camera.SortOrder)
For index = 0 To orderedCameras.Count() - 1
Dim iteratedCamera = orderedCameras.Skip(index).First()
FlowLayoutPanelCameras.Controls.SetChildIndex(iteratedCamera, index)
Next
-
Jul 20th, 2024, 01:19 PM
#4
Re: MDI Children Not Respecting Order
After several exchanges with ChatGPT, I was finally able to get it to work by clearing the FlowLayoutPanels controls and readding them:
Code:
Dim cameraWindows = FlowLayoutPanelCameras.Controls.OfType(Of FormCamera)
Dim orderedWindows = cameraWindows.OrderBy(Function(window) window.Camera.SortOrder).ToArray()
FlowLayoutPanelCameras.SuspendLayout()
FlowLayoutPanelCameras.Controls.Clear()
For Each cameraWindow In orderedWindows
If (Not cameraWindow.Camera.IsHidden) Then
FlowLayoutPanelCameras.Controls.Add(cameraWindow)
cameraWindow.Show()
End If
Next
FlowLayoutPanelCameras.ResumeLayout()
I don't particularly like this approach because ideally the I would like for the controls to remain and just set their z-index, but considering that nothing I tried worked c'est la vie.
If y'all have any other options, I'm certainly open to them.
-
Jul 20th, 2024, 10:00 PM
#5
Re: [RESOLVED] MDI Children Not Respecting Order
Can’t you just minimise the child windows, then restore them descending?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 20th, 2024, 11:00 PM
#6
Re: [RESOLVED] MDI Children Not Respecting Order
Originally Posted by .paul.
Can’t you just minimise the child windows, then restore them descending?
I just tested that and it behaves the same as described in post #3, I'm really at a loss for this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|