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 / August 2006

Tip: Looking for answers? Try searching our database.

Property in custom control, Visual Studio wont add design code even though its browsable.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh - 18 Aug 2006 03:08 GMT
I created a complex custom control using Visual Studio 2005 in C#. The
control has numerous properties, some of which Visual Studio cant seem
to create designer code for when I set its value in the property
browser. Below is the property that is giving me the most trouble in
the designer.

   [DefaultValue(true), Browsable(true)]
   public bool ShowCursor
   {
     get { return showCursor; }
     set
     {
       if (value && cursorTick == null)
       {
         cursorTick = new Timer();
         cursorTick.Tick += new EventHandler(cursorTick_Tick);
         cursorTick.Interval = CURSOR_TICK_INTERVAL;
         cursorTick.Start();
       }
       else if (!value && cursorTick != null)
       {
         cursorTick.Tick -= cursorTick_Tick;
         cursorTick.Stop();
         cursorTick = null;
       }
       showCursor = value;
     }
   }

It is supposed to add the code that sets the value of this property to
the value I set at design time in the property browser. Here is what im
talking about

     //
     // this is designer code for my control that VS2005 made
     //
     this.dataPresenterControl1.AllowKeyboardInput = false;
     this.dataPresenterControl1.AllowMouseInteraction = false;
     this.dataPresenterControl1.CursorIncrement = ((byte)(0));
     this.dataPresenterControl1.LineWidth = ((byte)(0));
     ...

It really burns me when Visual Studio does things like this. I have had
problems with custom control crashing Visual Studio because of
unhandled exceptions in my code which really sets me ablaze.
John Durrant - 21 Aug 2006 18:02 GMT
You need to make sure you set the value in your constructor.  Just
having a DefaultValue does not set it, it just informs the designer
what default you are using during the constructor.

> I created a complex custom control using Visual Studio 2005 in C#. The
> control has numerous properties, some of which Visual Studio cant seem
[quoted text clipped - 41 lines]
> problems with custom control crashing Visual Studio because of
> unhandled exceptions in my code which really sets me ablaze.
Josh - 27 Aug 2006 20:27 GMT
I figured out the problem, I do have values set for the properties
either in the contructor and in the variable declorations, that wasnt
the problem. the get accsesor needed to be changed

get { return (showCursor && cursorTick != null); }

Its because the cursor has many states, showCursor can be true and also
not show the cursor, its the way I implemented the logic and that was
the easiest  way I could do it, but it caused me trouble later on, but
now its fixed and I never need to touch it again.

> You need to make sure you set the value in your constructor.  Just
> having a DefaultValue does not set it, it just informs the designer
[quoted text clipped - 45 lines]
> > problems with custom control crashing Visual Studio because of
> > unhandled exceptions in my code which really sets me ablaze.

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.