Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / January 2008

Tip: Looking for answers? Try searching our database.

Preventing Visual Designer from overriding UserControl properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mario - 22 Jan 2008 14:05 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.