Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
We have an application that uses a parent form as a mdi container and all other forms as child forms.
On The parent form we have a control that has our 9 menu options on it, so that it doesn't have to be on each child form, but gets hooked up. So it's basically a global menu, but it causes a memory leak and with that it stills calls sometimes a closed forms menu events.

We want to redesign this or re-code it to get it working and not cause these memory leaks and other issues.

Does anyone know how to do a global menu or has a idea or know where I can get more information on it.

Thank you so long.
Posted
Comments
Sergey Alexandrovich Kryukov 22-May-15 2:35am    
Idea?! But what's the problem?
I have one idea: get rid of MDI, don't scare off your users.
—SA

1 solution

I have worked with client's applications that have MDI forms and their application cannot be modified otherwise, so support for the MDI pattern must be maintained. So I hope this helps.
I would look into all the form’s members that deal with MDI forms. Two that are useful are:

ActiveMdiChild
MDIChildren

These two can solve a lot of problems. Also, you can write code to facilitate this, for example; in sub ToolStripColorToRed_Click I use the form’s ActiveMdiChild property and in sub ToolStripColorToBlue_Click I used my code that is supported by the MDI and specific class frmChild.

Public Class Form1
    Delegate Sub ActiveFormDel(ByVal sender As Object, ByVal e As EventArgs)
    Delegate Sub FormSaysGoodByDel(ByVal sender As Object, ByVal e As EventArgs)
    Dim _formCount As Integer
    Dim _childForm As frmChild
 
    Private Sub ToolStripNewChildForm_Click(sender As Object, e As EventArgs) Handles ToolStripNewChildForm.Click
        Dim frm As New frmChild("New Child Form - " & _formCount.ToString,
                                AddressOf SetActiveForm, AddressOf GoodByMDIParent)
        frm.MdiParent = Me
        frm.Show()
        _formCount += 1
    End Sub
    Private Sub SetActiveForm(ByVal sender As Object, ByVal e As EventArgs)
        Try
            _childForm = DirectCast(sender, frmChild)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub GoodByMDIParent(ByVal sender As Object, ByVal e As EventArgs)
        Dim frm As frmChild = DirectCast(sender, frmChild)
        If frm Is _childForm Then
            _childForm = Nothing
        End If
        _formCount -= 1
    End Sub
    Private Sub ToolStripColorToRed_Click(sender As Object, e As EventArgs) Handles ToolStripColorToRed.Click
        If Me.ActiveMdiChild IsNot Nothing Then
            ActiveMdiChild.BackColor = Color.Red
        End If
    End Sub
    Private Sub ToolStripColorToBlue_Click(sender As Object, e As EventArgs) Handles ToolStripColorToBlue.Click
        If _childForm IsNot Nothing Then
            _childForm.BackColor = Color.Blue
        End If
    End Sub
End Class

Public Class frmChild
    Dim SetActive As Form1.ActiveFormDel
    Dim SayGoodBy As Form1.FormSaysGoodByDel
    Public Sub New(ByVal name As String, ByVal del As Form1.ActiveFormDel, ByVal del2 As Form1.FormSaysGoodByDel)
        SetActive = del
        SayGoodBy = del2
        ' This call is required by the designer.
        InitializeComponent()
        Text = name
        ' Add any initialization after the InitializeComponent() call.
 
    End Sub
    Private Sub frmChild_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        SetActive(Me, New EventArgs)
    End Sub
    Private Sub frmChild_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        SayGoodBy(Me, New EventArgs)
    End Sub
End Class




Regs,
Ron O.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900