mdi父级的全局菜单 [英] Global Menu on mdi parent
问题描述
我们有一个应用程序使用父窗体作为mdi容器,所有其他窗体用作子窗体。
在父窗体上,我们有一个控件,上面有9个菜单选项,所以它不必在每个子表单上,但会被连接起来。所以它基本上是一个全局菜单,但它会导致内存泄漏,并且有时仍会调用封闭的表单菜单事件。
我们想重新设计这个或重新设置编码让它工作,不会导致这些内存泄漏和其他问题。
有谁知道如何做全局菜单或有想法或知道我可以在哪里获得更多信息。
谢谢你。
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.
推荐答案
我使用过客户端的应用程序具有MDI表单且其应用程序不能以其他方式修改,因此必须维护对MDI模式的支持。所以我希望这会有所帮助。
我会查看处理MDI表单的所有表单成员。两个有用的是:
ActiveMdiChild
MDIChildren
这两个可以解决很多问题。此外,您可以编写代码来促进这一点,例如;在sub ToolStripColorToRed_Click中,我使用表单的ActiveMdiChild属性,在子ToolStripColorToBlue_Click中,我使用了MDI和特定类frmChild支持的代码。
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。
Regs,
Ron O.
这篇关于mdi父级的全局菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!