14
Method Of a Control Timer and ToolStrip Prepared by: Group 5

Timer control and Tool Strip C#

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

Page 1: Timer control and Tool Strip C#

Method Of a Control Timer and ToolStripPrepared by: Group 5

Page 2: Timer control and Tool Strip C#

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.

Page 3: Timer control and Tool Strip C#

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.

Page 4: Timer control and Tool Strip C#

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: 

Page 5: Timer control and Tool Strip C#

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: 

Page 6: Timer control and Tool Strip C#

private void timTimer_Tick(object sender, EventArgs e)          {              txtMain.AppendText(string.Format("Time: {0}\n", DateTime.Now.ToLongTimeString()));            }  

Code for the event

Page 7: Timer control and Tool Strip C#

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

Page 8: Timer control and Tool Strip C#
Page 9: Timer control and Tool Strip C#

 To add a toolbar to the top of your form, expand the Toolbox and locate the ToolStrip control.

ToolStrip

Page 10: Timer control and Tool Strip C#
Page 11: Timer control and Tool Strip C#
Page 12: Timer control and Tool Strip C#
Page 13: Timer control and Tool Strip C#
Page 14: Timer control and Tool Strip C#