Connecting Tech Pros Worldwide Help | Site Map

WinForms: DesignMode property is wrong!

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 21st, 2005, 12:17 PM
Lecture Snoddddgrass
Guest
 
Posts: n/a
Default WinForms: DesignMode property is wrong!

Hi,

When I create a UserControl-derived object, I often expose various
public properties. One of the things that I hate about the WinForms designer
is that if I decide to embed one of these controls in a form (or another
control), the designer likes to "touch" each of my custom properties --
either by trying to "set" it to a default value (null/zero) or trying to
"get" it's value. This is a real PITA because often times calling "get" on
these properties results in my code attempting to connect to another server,
retrieve some information, cache it, etc... While this is great at runtime,
it just doesn't make sense at design-time. Trying to "set" these properties
causes similar problems.

I make it a regular practice in the get/set handlers of my public
properties to always check the "DesignMode" property -- and if it's true,
I'll immediately return zero/null for the "get" or simply return immediately
for the "set"... This seems like a simple workaround for VS.NET's irritating
design-time behavior. The problem is that DesignMode doesn't always return
the correct value. It sometimes returns false even though the control is
being used in design mode. This happens when my UserControl-derived object
is placed in another UserControl-derived object which is then placed in
either a form or another control. In this nasty case, the DesignMode
property of my control will always return false even if my control is being
used in design mode. I'd be happy to write my own recursive DesignMode
checker that looks up the stack of parent controls... but even this is
impossible because DesignMode is a protected property, not public, so my
control has no way of checking the DesignMode property of its parents!

Is there a way around this tedious bug? This DesignMode thing is killing
me.

Thanks...



  #2  
Old July 21st, 2005, 12:18 PM
Claes Bergefall
Guest
 
Posts: n/a
Default Re: WinForms: DesignMode property is wrong!

Recursive DesignMode checker:
http://groups.google.se/groups?ie=UT....gbl&lr=&hl=sv

/claes

"Lecture Snoddddgrass" <maley@hamburg.fry> wrote in message
news:eG6OSHQ5DHA.2168@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi,
>
> When I create a UserControl-derived object, I often expose various
> public properties. One of the things that I hate about the WinForms[/color]
designer[color=blue]
> is that if I decide to embed one of these controls in a form (or another
> control), the designer likes to "touch" each of my custom properties --
> either by trying to "set" it to a default value (null/zero) or trying to
> "get" it's value. This is a real PITA because often times calling "get" on
> these properties results in my code attempting to connect to another[/color]
server,[color=blue]
> retrieve some information, cache it, etc... While this is great at[/color]
runtime,[color=blue]
> it just doesn't make sense at design-time. Trying to "set" these[/color]
properties[color=blue]
> causes similar problems.
>
> I make it a regular practice in the get/set handlers of my public
> properties to always check the "DesignMode" property -- and if it's true,
> I'll immediately return zero/null for the "get" or simply return[/color]
immediately[color=blue]
> for the "set"... This seems like a simple workaround for VS.NET's[/color]
irritating[color=blue]
> design-time behavior. The problem is that DesignMode doesn't always return
> the correct value. It sometimes returns false even though the control is
> being used in design mode. This happens when my UserControl-derived object
> is placed in another UserControl-derived object which is then placed in
> either a form or another control. In this nasty case, the DesignMode
> property of my control will always return false even if my control is[/color]
being[color=blue]
> used in design mode. I'd be happy to write my own recursive DesignMode
> checker that looks up the stack of parent controls... but even this is
> impossible because DesignMode is a protected property, not public, so my
> control has no way of checking the DesignMode property of its parents!
>
> Is there a way around this tedious bug? This DesignMode thing is[/color]
killing[color=blue]
> me.
>
> Thanks...
>
>[/color]


  #3  
Old July 21st, 2005, 12:22 PM
news.microsoft.com
Guest
 
Posts: n/a
Default Re: WinForms: DesignMode property is wrong!

Actually DesignMode property always return false in object constructor.
(yes, msdn doesnt include this) In practice you must place minimal code in
constructor, i'm overriding refresh method to workaround.

"Lecture Snoddddgrass" <maley@hamburg.fry> wrote in message
news:eG6OSHQ5DHA.2168@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi,
>
> When I create a UserControl-derived object, I often expose various
> public properties. One of the things that I hate about the WinForms[/color]
designer[color=blue]
> is that if I decide to embed one of these controls in a form (or another
> control), the designer likes to "touch" each of my custom properties --
> either by trying to "set" it to a default value (null/zero) or trying to
> "get" it's value. This is a real PITA because often times calling "get" on
> these properties results in my code attempting to connect to another[/color]
server,[color=blue]
> retrieve some information, cache it, etc... While this is great at[/color]
runtime,[color=blue]
> it just doesn't make sense at design-time. Trying to "set" these[/color]
properties[color=blue]
> causes similar problems.
>
> I make it a regular practice in the get/set handlers of my public
> properties to always check the "DesignMode" property -- and if it's true,
> I'll immediately return zero/null for the "get" or simply return[/color]
immediately[color=blue]
> for the "set"... This seems like a simple workaround for VS.NET's[/color]
irritating[color=blue]
> design-time behavior. The problem is that DesignMode doesn't always return
> the correct value. It sometimes returns false even though the control is
> being used in design mode. This happens when my UserControl-derived object
> is placed in another UserControl-derived object which is then placed in
> either a form or another control. In this nasty case, the DesignMode
> property of my control will always return false even if my control is[/color]
being[color=blue]
> used in design mode. I'd be happy to write my own recursive DesignMode
> checker that looks up the stack of parent controls... but even this is
> impossible because DesignMode is a protected property, not public, so my
> control has no way of checking the DesignMode property of its parents!
>
> Is there a way around this tedious bug? This DesignMode thing is[/color]
killing[color=blue]
> me.
>
> Thanks...
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.