Posted by webmaster Guido on April 12, 2001 at 15:30:17:
In Reply to: DateTimePicker posted by Judith on April 10, 2001 at 12:21:38:
: I would like to add a facility that will tell the user every
In your question you say "DateTimePicker", but that component is used for setting the date and/or the time, not for showing it.
1. Add a TLabel component to your form, e.g. Label1.
2. Add a TTimer component to your form, e.g. Timer1. Set its property Interval to 30000 (that's the time in milliseconds).
3. In the OnTimer event handler, show the time in the TLabel component:
4. Provide an on/off mechanism that enables/disables the timer and that also same time makes the label visible/invisible.
a. The easiest would be using a TCheckBox. In its OnClick event handler, write this code:
Label1.Visible := CheckBox1.Checked;
b. You can also use a TRadioGroup for the witching. To start with, add two lines to its Items property, for example "TIMER ON" and "TIMER OFF". In its OnClick event handler, write two lines of code:
Label1.Visible := (RadioGroup1.ItemIndex = 0);
c. If you use a TButton for switching, you should give some visible feedback to the user, showing if clicking the button will set the timer "On" or "Off". You could write an OnClick event handler like this:
Timer1.Enabled := not Timer1.Enabled;
The examples above are not finished, there's still room for improvements, like:
** Setting the necessary component properties when the program starts (in the form's OnCreate or OnShow event handler).
** Not only show the time when the timer is fired, but also each time that is enabled -- if you build and run the program, you'll see what I mean.
A final tip: during the testing phase, it migh t be wise to set the timer's interval to 1000 instead of the final 30000 ;-)