English 中文(简体)
是否需要明确处理定制的背景材料
原标题:Do I need to explicitly dispose a customized contextmenustrip

我有一个类别<代码>,包括我可以在不同控制下使用的背景材料矩阵。

    Friend Sub New(ByRef objControl As System.Windows.Forms.Control)

    m_objControlContainer = objControl
    m_mnuCopyCell2Clipboard = New ToolStripMenuItem("Copy Cell")
    m_PopupMenu = New ContextMenuStrip
    m_PopupMenu.Items.AddRange(New ToolStripMenuItem() {m_mnuCopyCell2Clipboard})
End Sub

例如,我可在数据GridViewDGVTable:中使用。

 Private m_objPopUpMenu As clsContextPopUpMenu
 m_objPopUpMenu = New clsContextPopUpMenu(CType(DGVTable, System.Windows.Forms.Control))

但是,注意到<代码>m_objPopUpMenu。 IS NOT与上述数据网格表有关的表格。 根据背景材料MenuStrip Constructionor在MSDN的解释,我认为,m_objPopUpMenu不能自动处理,因为它不是形式上的儿童。

我的问题是,我是否必须在设计师中明确处置<条码>m_objPopUpMenu:

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
            **m_objPopUpMenu.Dispose()**
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

一个更广泛的问题是,我何时处置物体/资源? 当然,采集器不是释放所有现有记忆的魔鬼。 Can 我始终如上所示处置分处置物/资源。

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 由于对问题有了更好的了解,订正的答复:

由于环境标准的实施 可以识别,你要么需要在表格管理的构成部分清单中添加,以便按照你原来的问题的建议,适当和自动处理或管理处置。

这里,对您的班级进行了修订,以支持自动处置,如果你将“EmnuStrip”直接添加到以下表格中的话,窗口将处理:

Friend Sub New(ByVal objControl As System.Windows.Forms.Control, ByVal components As System.ComponentModel.IContainer)

    m_objControlContainer = objControl
    m_mnuCopyCell2Clipboard = New ToolStripMenuItem("Copy Cell")
    m_PopupMenu = New ContextMenuStrip(components)
    m_PopupMenu.Items.AddRange(New ToolStripMenuItem() {m_mnuCopyCell2Clipboard})
End Sub

3. 在您的表格或用户控制范围内召集这一新建筑商:

 Private m_objPopUpMenu As clsContextPopUpMenu
 m_objPopUpMenu = New clsContextPopUpMenu(DGVTable, Me.components)

请注意,由于不需要,我也从建筑商删除了<条码>ByRef,这还消除了在将控制带往建筑商之前必须进行控制。

另一项说明是(“当天的反馈”)各组成部分不一定出现在每一种形式或用户控制上。 我认为,这种情况已经改变/改变,但是如果你认为没有变化,就很容易人工添加:

Private components As System.ComponentModel.IContainer

贵方:

Me.components = New System.ComponentModel.Container()

在您的处置方法中(如果不存在,我增加了完全处置方法;如果只是增加了与部件有关的代码):

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
        If Not (components Is Nothing) Then
            components.Dispose()
        End If
    End If
    MyBase.Dispose(disposing)
End Sub
问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签