Problems with inheriting ToolbarButton

  • Thread starter Thread starter Kohinoor Basu
  • Start date Start date
K

Kohinoor Basu

Hi,

I have created a new class called MyToolbarButton which inherits from
ToolbarButton class.

I add a new toolbar into a form and add some buttons to that toolbar. Then
I manually change the declaration of ToolBarbutton in the form to
MyToolbarButton. The code compiles fine. But when I try to execute the
code I get the following exception.

===============================================================
An unhandled exception of type 'System.TypeLoadException' occurred in
WindowsApplication2.exe

Additional information: Declaration referenced in a method implementation
can not be a final method. Type: WindowsApplication2.MyToolBarButton.
Assembly: Dispose.
===============================================================

Anybody has any idea why I am getting this error.

Kohinoor Basu
 
Hi Jay,

This is what I got. It still gives me the error. Any help will be
appreciated.

========================= Begin Code ===================================
Imports System.Windows.Forms
Imports System.ComponentModel

Imports System.ComponentModel.Design

Public Class MSToolBarButton : Inherits ToolBarButton

Private m_objMenuItem As MenuItem

Public Sub New(ByVal Parent As MenuItem)

MyBase.New()

m_objMenuItem = Parent

End Sub

Public Overloads Overrides Sub Dispose()

m_objMenuItem.Dispose()

MyBase.Dispose()

End Sub



Public Shadows Property Visible() As Boolean

Get

Visible = MyBase.Visible

End Get

Set(ByVal Value As Boolean)

MyBase.Visible = Value

If Not (m_objMenuItem Is Nothing) Then

m_objMenuItem.Visible = Value

End If

End Set

End Property

End Class

Public Class MSToolBarButtonCollectionEditor : Inherits CollectionEditor

Public Sub New(ByVal type As System.Type)

MyBase.New(type)

End Sub

Protected Overrides Function CreateNewItemTypes() As System.Type()

Return New Type() {GetType(MSToolBarButton)}

End Function

End Class

Public Class MSToolbar : Inherits ToolBar

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

Editor(GetType(MSToolBarButtonCollectionEditor), _

GetType(System.Drawing.Design.UITypeEditor))> _

Public Shadows ReadOnly Property Buttons() As _

ToolBar.ToolBarButtonCollection

Get

Return MyBase.Buttons()

End Get

End Property

End Class

========================= End Code ===================================
 
Kohinoor,
Which version of VS.NET?

VS.NET 2003 will not allow me to compile it, as ToolBarButton.Dispose() is
not overridable!

MSToolBarButton.vb(19): 'Public Overrides Overloads Sub Dispose()' cannot
override 'Public Overridable NotOverridable Sub Dispose()' because it is
declared 'NotOverridable'.

VS.NET 2002 does not report an error, however ToolBarButton.Dispose() is
not overridable in either VS.NET 2002 or VS.NET 2003.

You should override this version of the Dispose method:
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)

Hope this helps
Jay
 
Back
Top