How to make the Designer understand my Mew sub

  • Thread starter Thread starter TryingLikeHeck
  • Start date Start date
T

TryingLikeHeck

I have a UserControl that must have 2 fields initialized before some of the
prorperties are used. So I added a new New sub with arguments.

If I leave the old New in there the control could be used without initializing
these fields so I removed it.

Now if I try to use it the designer gets upset because there is no New()

Is it posible to use only a New with arguments and still use the control in the
Designer??


Thanks in advance
 
This is where using Me.DesignMode is useful, or validating your properites
before you actually use them. The Designer (VSIDE) only calls the 0
argument constructor (unless there is some really fancy attribute I don't
know if). However, like I said, you can just validate your variables, and
when a property is set, call a method to do whatever it is your user control
needs to initialize from the same constructor.

-CJ
 
Lots of code I was hoping to avoid, but I want to use the Designer so I have
to work with its limitations.

Thanks for the info. At least I now know not to keep trying
 
It's really not that bad. Just do some fun tricks with it. like if you run
validation routines inside your properties at all, you can just reset them
to themselves and it will re run it with the same values. i.e.
me.propertyname = me.propertyname

Kinda fun way to do it. =)

-CJ
 
active said:
Lots of code I was hoping to avoid, but I want to use the Designer
so I have to work with its limitations.

OK, I'm new to this, but...

Could use add the niladic constructor (assigning "sensible" default
values for use in the Designer) but throw an Exception if its called
from outside the Designer?

Just a thought...
Phill W.
 
I have a UserControl that must have 2 fields initialized before some of the
prorperties are used. So I added a new New sub with arguments.

If I leave the old New in there the control could be used without initializing
these fields so I removed it.

Now if I try to use it the designer gets upset because there is no New()

Is it posible to use only a New with arguments and still use the control in the
Designer??


Thanks in advance

Could you do something like this? As long as you work in debug mode, the
designer can use the parameterless constructor. When you're ready to
compile to release mode, then the code is not included?

#If Debug
Public Sub New()
'Code
End Sub
#Endif

Public Sub New(parameters)
MyBase.New
InitializeComponents
End Sub

Just an idea
 
* " active said:
Lots of code I was hoping to avoid, but I want to use the Designer so I have
to work with its limitations.

I wouldn't consider this to be a "limitation". It's a good
compromiss...
 
Back
Top