Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# User control with timer starts even in design mode

Tags:

c#

timer

I have the following problem:

I made a user control library (DLL), which just has an enabled Timer. When I try to use this control in an application, as soon as I drag it to the Form in design mode, it starts to count! Even if the application is not running.... How can I avoid that?

My objective is that the Timer starts counting as soon as the application is launched, but not in Design Mode... because the Timer uses some external functions that cause the crash in the Design Mode.

Thank you in advanced!

Dario

like image 746
user2917354 Avatar asked Feb 14 '23 15:02

user2917354


1 Answers

You can check the DesignMode property of Control:

if (!this.DesignMode) {
    // its not in design mode.. so do stuff.
}

Or perhaps neater:

yourTimer.Enabled = !this.DesignMode;
like image 96
Simon Whitehead Avatar answered Mar 06 '23 11:03

Simon Whitehead