views:

32

answers:

1

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 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.

+1  A: 

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
Hans Passant
Unfortunately I can't use that. I need to inherit from the ToolboxItem attribute so that I can determine whether it should be added to the toolbox based on a license. I've tried the toolboxitem class but to no avail.
Jules
Hmm, that wasn't clear from your question, I wouldn't have bothered researching this approach if I knew. ToolBoxService.GetToolBoxItem(s) properly hides the class with your attribute. Clearly it is not actually used to populate the toolbox. Use the built-in support for licensing instead, start at the License class for info.
Hans Passant