Introduction
This code snippet defines methods for Back and Forward buttons for MDI parent forms to show all opened MDI child forms one by one.
Using the code
One can implement the below code in a button click or in any event as applicable.
In this article, the code is implemented within the click event of menu items.
Private Sub BACKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BACKToolStripMenuItem.Click
Try
Dim t As New Form
For Each f As Form In Application.OpenForms
If f IsNot Me.ActiveMdiChild Then
t = f
Else
t.Activate()
Return
End If
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FORWARDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FORWARDToolStripMenuItem.Click
Try
Dim t As New Form
For i As Integer = Application.OpenForms.Count - 1 To 0 Step -1
Dim f As Form = Application.OpenForms(i)
If f IsNot Me.ActiveMdiChild Then
t = f
Else
t.Activate()
Return
End If
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Points of Interest
This method is actually 'old school' and can be refined in numerous ways.