473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...
Jul 21 '05 #1
2 7469
Recursive DesignMode checker:
http://groups.google.se/gr**********....gbl&lr=&hl=sv

/claes

"Lecture Snoddddgrass" <ma***@hamburg.fry> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
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...

Jul 21 '05 #2
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" <ma***@hamburg.fry> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
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...

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4919
by: Tiago Barbutti | last post by:
I have a UserControl that execute methods in Load event, but it hapens in designMode and generate an error and the control disappear from the form. I read that i can use the DesignMode to kwnow...
0
1012
by: PW | last post by:
I have a UserControl that executes a method in its constructor. The method contains client/server code which populates a ComboBox in the UserControl. I have a few problems with this: 1) The...
3
1132
by: Galore | last post by:
Hello, In winforms, we had the DesignMode property, to know when we're developing code or executing the application. I wonder if is there something similar in webforms. I need to write a...
2
5937
by: Malleier Alfred | last post by:
Hi, what does the Me.DesignMode-Property turn back. I tried to set a MsgBox(Me.DesignMode) in my form's and control's Sub New(), but it allways turns back 'false', even if the form or control is...
29
5042
by: Charles Law | last post by:
Further to my issue about user controls, I have a problem with DesignMode. Here is the project hierarchy: MainApp |_ Project1 |_ SubProject (UserControl) SubProject has a default constructor...
1
2187
by: Paul W | last post by:
I'm having trouble detecting whether my Control is in DesignMode. I'm deriving a class from TreeView; Public Class ExplorerView Inherits TreeView ... End Class
2
409
by: Lecture Snoddddgrass | last post by:
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...
2
2266
by: Simon Rigby | last post by:
Hi folks, I'm trying to switch an iFrame in and out of design mode by way of a script. As you can see from the method it is intended to be cross browser compatible (or FF and IE at least). The...
2
4469
by: graeme g | last post by:
ii i've been developing some usercontrols... and sudden the property designmode no longer works.. if i test it value at designtime it always comes back false... i've made a work around if...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.