Click here to Skip to main content
Click here to Skip to main content

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

, 27 Feb 2014
Rate this:
Please Sign up or sign in to vote.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sarath Jayachandran

United Arab Emirates United Arab Emirates
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 27 Feb 2014
Article Copyright 2014 by Sarath Jayachandran
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid