Upload
jj-javier
View
111
Download
6
Tags:
Embed Size (px)
DESCRIPTION
C# Timer control - think for Stopwatch Tool strip - Think for a toolbox of a browser below the menu bar! Artist and Programmer! the best! #JJ javier
Citation preview
Method Of a Control Timer and ToolStripPrepared by: Group 5
Method of a Control Timer
The Timer control allows you to set a time interval to execute an event after some interval continuously. It is useful when you want to execute certain applications after a certain interval.
Properties Description
EnabledProperty used to Get or set
whether the timer is running.
IntervalProperty used to set or get
the time in millisecond between the timer clicks.
Methods
Events Description
Start Method used to start timer.
Stop Method used to stop timer.
Event
Events Description
TickTriggered when the time
interval has elapsed.
Example: Let's make a small forms application that displays a message every second (every 1000 ms that is). We add two buttons (btnStart, btnStop) and a textbox (txtMain) to a form. After that we add a timer control (timTimer) by dragging the timer control onto the form. The timer control will then be represented by a small icon below, it will look like this:
After that we alter the properties of the control and set the .Interval property to 1000ms:
Then we take a look at the event list (by pressing the yellow flash above the properties) and we can see that there is only one event, Tick. Double click on it to open it up for editing:
private void timTimer_Tick(object sender, EventArgs e) { txtMain.AppendText(string.Format("Time: {0}\n", DateTime.Now.ToLongTimeString())); }
Code for the event
private void btnStart_Click(object sender, EventArgs e) { timTimer.Enabled = true; } private void btnStop_Click(object sender, EventArgs e) { timTimer.Enabled = false; }
Code for the Button
To add a toolbar to the top of your form, expand the Toolbox and locate the ToolStrip control.
ToolStrip