|
-
February 3rd, 2010, 06:19 PM
#1
Animated User Controls in Design Mode
I drag my Windows Forms User Control onto my form in design mode.
One of the properties of the User Control is, "Boolean Animate = false;".
This property can be changed in design mode using the Properties form within Visual Studio as it has a [Desciption("..."), Category("...")] attribute.
If it is set to true, then some text spins around (for example) and takes say 5 seconds to complete it's animation.
In design mode this is a pain (imagine having 10 of these User Controls on your form). In design mode, I just want some visual indication that the text will spin. At runtime, it should do the actual spin.
Ok, I can do all of that, but I just wanted to confirm one thing with you guys here.
Do you use...
Code:
if (DesignMode)
{
// simple visual indication
}
else
{
SpinTheText();
}
to prevent this or is there an alternative technique?
It just seems to me that the design only happens once (ok maybe a few times), whereas the application will be run many times and the "if (DesignMode)" becomes an overhead at runtime.
I understand that there will be Timer's involved in the animation and one option is to not start the Timer in design mode, but the point of this post is to determine whether "if (DesignMode)" is the way to go.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
February 3rd, 2010, 06:35 PM
#2
Re: Animated User Controls in Design Mode
Just check for design mode once while initializing the control. If not in design mode, then start the timer.
If you only check it once during initialization, you won't have a perf hit when running.
-
February 3rd, 2010, 06:42 PM
#3
Re: Animated User Controls in Design Mode
And by "During Initialisation", do you mean in the Constructor or the Load event?
I'm just looking for reasons/pros/cons of where to do what etc.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
February 3rd, 2010, 06:47 PM
#4
Re: Animated User Controls in Design Mode
 Originally Posted by Arjay
Just check for design mode once while initializing the control. If not in design mode, then start the timer.
If you only check it once during initialization, you won't have a perf hit when running.
I'm not sure about later versions of .NET, sor correct me if I am wrong, but in .NET 2.0 the DesignMode property is broken. I remember having to implement it myself for one of my custom controls.
-
February 3rd, 2010, 06:58 PM
#5
Re: Animated User Controls in Design Mode
Also, the Animate property could be set at 'runtime', so in it's set {} I will also need to check for DesignMode (runtime overhead)
Obviously I'm aiming to only have the Timer running when Animation is actually happening (even at runtime).
I'm thinking maybe when the Timer is fired. In that event maybe the only place I need to check DesignMode. Eg of the top of my head...
if (DesignMode && timer.Enabled) // runtime overhead
timer.Stop();
However, I'm still 100% that the Timer should not be started in the first place if we are in design mode.
I'm sure there is ideal logic for this kind of thing.
Last edited by rliq; February 3rd, 2010 at 07:00 PM.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
February 3rd, 2010, 07:09 PM
#6
Re: Animated User Controls in Design Mode
 Originally Posted by BigEd781
I'm not sure about later versions of .NET, sor correct me if I am wrong, but in .NET 2.0 the DesignMode property is broken. I remember having to implement it myself for one of my custom controls.
You could be right. What did you do to implement it yourself?
-
February 3rd, 2010, 07:13 PM
#7
Re: Animated User Controls in Design Mode
 Originally Posted by rliq
Also, the Animate property could be set at 'runtime', so in it's set {} I will also need to check for DesignMode (runtime overhead)
Obviously I'm aiming to only have the Timer running when Animation is actually happening (even at runtime).
I'm thinking maybe when the Timer is fired. In that event maybe the only place I need to check DesignMode. Eg of the top of my head...
if (DesignMode && timer.Enabled) // runtime overhead
timer.Stop();
However, I'm still 100% that the Timer should not be started in the first place if we are in design mode.
I'm sure there is ideal logic for this kind of thing.
I would go with only checking for design mode once. So do the check somewhere (probably in OnLoad) and not fire the timer rather than checking on each timer event.
You need to do this check where Design time can be checked and the constructor may not be the proper place. Maybe Ed can share some experience here?
-
February 3rd, 2010, 07:13 PM
#8
Re: Animated User Controls in Design Mode
 Originally Posted by Arjay
You could be right. What did you do to implement it yourself?
hehe... trying to remember now...
Ok, found my old project. You can do it using another .NET class, just not Component.DesignMode
Code:
using System.ComponentModel;
static class EnvironmentState
{
/// <summary>
/// This is a working implementation of the Component.DesignMode property.
/// To avoid a .NET 2.0 bug (http://www.csharp-architect.com/designmodewinformsissue.aspx)
/// use this method instead. The 'bug' (they don't seem to want to fix it, so maybe it
/// is by design) causes any class derived from UserControl to return "false" regardless
/// of the current mode.
/// </summary>
public static bool DesignMode
{
get
{
return ( LicenseManager.UsageMode == LicenseUsageMode.Designtime );
}
}
}
And yes, as Arjay mentioned I simply checked for (my implementation of) DesignMode once where it was needed. In your case that would be before you start the timer.
Last edited by BigEd781; February 3rd, 2010 at 07:15 PM.
-
February 3rd, 2010, 10:07 PM
#9
Re: Animated User Controls in Design Mode
So at the end of the day "DesignMode" is the correct way to go about it. Seems reasonable, as a User Control needs to work at both design time and run time. Thanks for your input.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|