Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Inheriting from ToolBar

I have created a class that inherits from System.Windows.Forms.ToolBar. In that class, I add buttons to the toolbar and I handle events. Those buttons are declared public (Public tlbOpen As ToolBarButton) so they can be accessed easily from the caller.

Now, when I place my control on a form, it displays correctly with all the buttons. However, if I change properties of the buttons, it doesn't generate the code.

With a normal ToolBar, it does something like this:
Dim tlbOpen As ToolBarButton
tlbOpen.Visible = False
myToolBar.Buttons.Add(tlbOpen)

However, what *should* be generated in my case is this:
myCustomToolBar.tlbOpen.Visible = False

how could I solve this? any idea?

Etienne Charland
Thursday, September 19, 2002

Take a look at the DesignerSerializationVisibilityAttribute class.

In this case you would want to apply the attribute to the property as:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool Visible
{
    ...

Matt Kennedy
Thursday, September 19, 2002

I played with this. I put all my buttons private, and put a public property for each button. If I set DesignerSerializationVisibility to Visible, wich is the default, it doesn't generate the code. If I set it to content, it will set the properties of the button and add it to the toolbar again!

Etienne Charland
Friday, September 20, 2002

*  Recent Topics

*  Fog Creek Home