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.
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.