Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Back and Forward button for MDI Parent form to traverse through opened MDI child forms

0.00/5 (No votes)
27 Feb 2014 1  

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here