470,636 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

How to stop designer from assigning values to usercontrol properti

Jim
I have some complex (fairly) user controls that I have created. Some of
those user controls host other user controls. When I host one of these on a
WinForm, I sometimes run into problems where the designer blows up with an
"Object Reference Not Set to an Instance of an Object". Sometimes it even
(so kindly) "munches" my code in the hosting control. Unfortunately, it
seldm if ever tlss "where" exactly the problem occurred, and to my knowledge
there is no way to run the designer in debug mode and stop through what it's
doing.

My fix, for now, as been to put a "if( !DesignMode) test around al of the
set / get fxns in my properties. This works (usally.... Although under
certain circumstants, the designer has apparently not set the value of the
DesignMode property by the time these properties are getting configured.)
All this fact-checking in my propertis is superfluous, were it not for the
fact that the designer always wants to assign values to them that sometimes
do not make sense. Especially and most particularly when the properties take
objects as their values, and the designer is trying to assign "NULL" to them.

Is there some attribute that I can assign to my properties that will prevent
the designer from trying to retreive values from, or assign values to them
while rendering the control in design mode? I have seen the [Borwseable()]
attribute, but that doesn't seem to fully cover it. Is there a collection of
information on these attributes somewhere that I can read up on? Surely
there has to be a better way to do this other than what I am currently having
to do.

Thanks for any help. :)

JIM

Nov 17 '05 #1
2 1786
You might want to try to assign default values to your member variables when
you declare them. That way when the designer generates the code for you it
will have a value to use.

public class Test
{
protected string m_name = "";

public Test()
{
...
}

public String Name
{
get { return m_name; }
set { m_name = value; }
}
}

See if this helps.
Dennis
"Jim" wrote:
I have some complex (fairly) user controls that I have created. Some of
those user controls host other user controls. When I host one of these on a
WinForm, I sometimes run into problems where the designer blows up with an
"Object Reference Not Set to an Instance of an Object". Sometimes it even
(so kindly) "munches" my code in the hosting control. Unfortunately, it
seldm if ever tlss "where" exactly the problem occurred, and to my knowledge
there is no way to run the designer in debug mode and stop through what it's
doing.

My fix, for now, as been to put a "if( !DesignMode) test around al of the
set / get fxns in my properties. This works (usally.... Although under
certain circumstants, the designer has apparently not set the value of the
DesignMode property by the time these properties are getting configured.)
All this fact-checking in my propertis is superfluous, were it not for the
fact that the designer always wants to assign values to them that sometimes
do not make sense. Especially and most particularly when the properties take
objects as their values, and the designer is trying to assign "NULL" to them.

Is there some attribute that I can assign to my properties that will prevent
the designer from trying to retreive values from, or assign values to them
while rendering the control in design mode? I have seen the [Borwseable()]
attribute, but that doesn't seem to fully cover it. Is there a collection of
information on these attributes somewhere that I can read up on? Surely
there has to be a better way to do this other than what I am currently having
to do.

Thanks for any help. :)

JIM

Nov 17 '05 #2
There is in fact a way to run the entire Visual Studio Designer in
debug mode and find out exactly what the problem is in your control.
There is an MSDN article, but I can't find it right now. You might want
to inquire in the microsoft.public.dotnet.windowsforms.designtime
newsgroup.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jim | last post: by
6 posts views Thread by TryingLikeHeck | last post: by
reply views Thread by Adam Right | last post: by
1 post views Thread by Korara | last post: by
???
reply views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.