Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello

In my program , i use Timer Setting .
But i want to make, user can choose any seconds.
Timer setting can set any time by user(No Fix time).

How to do ?
Pls give me advice.
Posted
Comments
[no name] 12-Dec-13 9:27am    
what is the problem with timer? and what do you wants actually.
Sergey Alexandrovich Kryukov 12-Dec-13 9:30am    
First of all, why?
The question is not clear.
—SA
BillWoodruff 12-Dec-13 9:38am    
Do you want the user to stop and start the Timer, or, is the Timer always running, or only started, and stopped, in your code ?

Does the Timer run once, or is the Timer ... once started ... allowed to run for a certain amount of time, or until the user stops it ?
Member 10404120 12-Dec-13 10:42am    
User can start used by Timer , when he want to start run for a certain amount of time and stop.
Like as advance set time by timer.
BillWoodruff 12-Dec-13 14:59pm    
You mention, in one of your responses here, a DateTimePicker. If you want specific help please describe the user interface you desire in as much detail as possible.

You might also describe what it is you wish to start, and stop, when the Timer starts, and stops.

Easiest way is to set a Timer to in interval less that the user can select: so if he can select in seconds, set the Timer.Interval to 250 (or 1/4 second).
When the user enters a value, multiply it by the timer value (in this case 1000/250 (one second in milliseconds divided by the interval of the timer) and save that to a class level variable.
In the Timer.Tick event, check the class level variable, and if it is non-zero decrement it by one and check it again. If it is now zero, the user timeout has expired.
 
Share this answer
 
Comments
Member 10404120 12-Dec-13 9:43am    
How to link with Timer Interval and user choose time ?
OriginalGriff 12-Dec-13 9:53am    
Read what I said - it's not complex!
Member 10404120 12-Dec-13 10:30am    
Thanks
But i don't want to Timer set in Time Interval from Properties.
Time only change from DateTimePicker.
Member 10404120 12-Dec-13 10:35am    
Thanks
I don't want to change Timer set in interval of Timer Properties.
User easily to changed by DateTimePicker/TextBox .
OriginalGriff 12-Dec-13 10:58am    
If you read what I said, you don't change the timer at all - it sits and runs, ticking away avery 1/4 second, and you count down from the value the user entered.
Every time the user changes the value, you reset the value of the variable the tick event is decrementing...
What's the problem?

Get interval[^] value from user (using variable) and set Timer.Interval property ;)
 
Share this answer
 
Comments
Member 10404120 12-Dec-13 9:43am    
How to link/interface with Timer Interval and user choose time ?
Maciej Los 12-Dec-13 12:19pm    
Not sure what you mean, but...
int ValueFromUser = Int32.Parse(TextBox1.Text);
Timer1.Interval = ValueFromUser;
Manfred Rudolf Bihy 12-Dec-13 13:53pm    
Not sure what user enters, but it may not be milliseconds. So there may be need for a Timer1.Interval = ValueFromUser * 1000;
Maciej Los 12-Dec-13 13:56pm    
Good point, Manfred.
Thank you ;)
There are many ways in which you could do this. You can have a trackbar.
C#
ints.Timer = trackBar1.Value * 1000;
Timer.Interval = ints.Timer;
//ints is my class with all the values.
//we have to multiply the trackBar1.Value by 1000 to get 1 second interval.
//1 tick in timer equals 0.001 seconds in real life.


or with a textbox:
C#
ints.Timer = Convert.ToInt32(textbox1.Text);
Timer1.Interval = ints.Timer


There are more ways, but this one is more common.
 
Share this answer
 
v2
Set the timer's interval to one second:
C#
Timer1.Interval = 1000;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900