Custom Control Designer Questions

instantmaker

New member
Joined
Aug 30, 2009
Messages
4
Programming Experience
1-3
Hi all,

I have a simple custom control with a button on it (composite control). Which I override the Text property so that in the property page I can set the "Text" property to reflect the text on the button. However, everytime when I recompile the control, the text on the button will go back to "button1". For example, if I dropped that custom control on a form and tried to change its Text property to some other text, like "Click Me". As soon as I recomplie the composite control itself, it will go back to "Button1". I suspect that it is because the default text on the button itself is "button1". My question is that if there is a way to keep the text?

Any help would be appreicated. Thanks
 
Hello.

Could you post the Property which you use to set the text?

Best Regards,
Bobby

The property looks like this


VB.NET:
Public Property Shadows Text() As String
      Get
            Return Button1.Text
      End Get
      Set(ByVal value As String)
            Button1.Text = Value
      End Set
End Property

I don't have Visual Studio with me at the moment, but it should look close enough. Thanks for helping in advance.
 
Try something like this:
VB.NET:
<Browsable(True)> _
Public Property ButtonText() As String
    Get
        Return button1.Text
    End Get
    Set(ByVal Value As String)
        button1.Text = Value
    End Set
End Property
The browsable attribute will show the property in the designer. :cool:
 
Try something like this:
VB.NET:
<Browsable(True)> _
Public Property ButtonText() As String
    Get
        Return button1.Text
    End Get
    Set(ByVal Value As String)
        button1.Text = Value
    End Set
End Property
The browsable attribute will show the property in the designer. :cool:

I did try that. Actually I found a solution how to keep the text after recompiling. what I did was to include <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> on the property...that way it will keep the user settings. Also you are correct that I needed to include <Browsable(True)> _ to expose the property to the property window in the designer.

Thanks
 
Back
Top