I have been having quite a bit of trouble with the Visual Designer
ransacking my properties. In the UserControl I created there are
three optional buttons (Add, Edit, and Remove). Each button has a
property which exposes that button's visibility. (e.g. ShowAddButton)
I have assigned a DefaultValue of True to each of the buttons using
Design Time Attributes. All is well to this point. The control works
just fine.
Trouble is, at some point I make changes with the Visual Designer to
other parts of the form that include my custom UserControl. When this
happens, all the buttons on all instances of that control disappear,
that is, their visibility property is set to False. As long as I
don't interact with the Visual Designer this doesn't seem to be
happening. My belief is that when the Visual Designer regenerates the
designer code, it also regenerates all the attributes and makes the
wrong assumption about what the ShowAddButton, etc. values should be.
Why is this, especially when I have set the DefaultValue to True. I
just want the Designer to leave my code alone.
Any ideas how I can prevent the Visual Designer from ransacking my
designer code?
Here's an example of one of the properties I'm referring to:
<System.ComponentModel.DefaultValue(True), _
System.ComponentModel.Description("Indicates whether the Remove
Button should be displayed.")> _
Public Property ShowRemoveButton() As Boolean
Get
Return Me.btnRemove.Visible
End Get
Set(ByVal value As Boolean)
Me.btnRemove.Visible = value
End Set
End Property
Mario - 22 Jan 2008 20:36 GMT
Got this from a coworker and upon first tests it appears to be
working:
Using the Visible property has given me problems in the past. Try
changing it to something like this and see if it works any better.
Private mblnShowRemoveButton As Boolean = True
<System.ComponentModel.DefaultValue(True), _
System.ComponentModel.Description("Indicates whether the Remove
Button should be displayed.")> _
Public Property ShowRemoveButton() As Boolean
Get
Return mblnShowRemoveButton
End Get
Set(ByVal value As Boolean)
mblnShowRemoveButton = value
Me.btnRemove.Visible = value
End Set
End Property