Problem deriving from ToolboxItemAttribute in .Net, Winforms
As an example, here's a simple attribute, derived from ToolboxItemAttribute:
<ToolboxItemX(False)> _
Public Class Class1
Inherits Button
End Class
Public Class ToolboxItemXAttribute
Inherits ToolboxItemAttribute
Public Sub New(ByVal defaultType As Boolean)
MyBase.New(defaultType)
End Sub
End Class
The problem is that when I show the toolbox, Class1 is appearing in it. It's as if my attribute is ignored, and so the default toolboxitem attribute is used.
I've used reflector to 开发者_JAVA百科look at the logic of ToolboxService.GetToolboxItem and as far as I can see, it should pick up my attribute and see that the item should not be displayed in the toolbox.
PS: I've tried resetting the toolbox, closing the ide and reopening etc.
The Windows Forms toolbox is remarkably cranky. This ought to work, but indeed doesn't. No idea why, this code is locked up inside Visual Studio. As a workaround, you can hide it by using the DesignTimeVisibleAttribute. Like this:
<ToolboxItemX(False)> _
<DesignTimeVisible(False)> _
Public Class Class1
Inherits Button
End Class
精彩评论