You are on page 1of 8

Program Stopwatch Hingga Microsecond

Ditulis oleh Administrator Minggu, 22 November 2009 12:51 - Terakhir Diperbaharui Minggu, 22 November 2009 12:54

#using #using #using using namespace System; using namespace System::Diagnostics; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::Drawing::Drawing2D; // The following class represents a simple stopwatch form with // start, stop, reset, and lap time functions. public ref class Form1: public System::Windows::Forms::Form { private: Stopwatch^ stopWatch; Boolean captureLap; public: Form1() { stopWatch = gcnew Stopwatch; captureLap = false; InitializeComponent(); } public: ~Form1() { } private: // Define event handlers for various form events. void buttonStartStop_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { // When the timer is stopped, this button event starts // the timer.  When the timer is running, this button // event stops the timer. if ( stopWatch->IsRunning ) { // Stop the timer; show the start and reset buttons. stopWatch->Stop(); buttonStartStop->Text = "Start";

1/8

labelLap->Visible = false. update the displayed timer // value for each tick event. this button  // event captures a lap time. if ( buttonLapReset->Text->Equals( "Lap" ) ) { if ( stopWatch->IsRunning ) { // Set set the object state so that the next // timer tick will display the lap time value. } } else { // Reset the stopwatch and the displayed timer value. labelLapPrompt->Visible = false. stopWatch->Start().00". if ( stopWatch->IsRunning ) 2/8 . captureLap = true. labelLapPrompt->Visible = false. this button event resets // the timer. labelTime->Text = "00:00:00. } } void buttonLapReset_Click( System::Object^ /*sender*/.Terakhir Diperbaharui Minggu. } else { // Start the timer. System::EventArgs^ /*e*/ ) { // When the timer is running. buttonLapReset->Text = "Lap". labelLapPrompt->Visible = true. labelLap->Visible = true. show the stop and lap buttons. 22 November 2009 12:51 . 22 November 2009 12:54 buttonLapReset->Text = "Reset". labelLap->Visible = false.Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu. System::EventArgs^ /*e*/ ) { // When the timer is stopped. buttonStartStop->Text = "Stop". } } void timerMain_Tick( System::Object^ /*sender*/. buttonLapReset->Text = "Lap".  When the timer is running. stopWatch->Reset().

labelTime->Text = String::Format( "{0:00}:{1:00}:{2:00}. ts. } void labelTopLeft_Click( Object^ /*sender*/. this->Close(). TimeSpan ts = stopWatch->Elapsed.Screen::PrimaryScreen->WorkingArea. if ( captureLap ) { labelLap->Text = labelTime->Text. 22 November 2009 12:51 . ts. ts.Terakhir Diperbaharui Minggu. 22 November 2009 12:54 { // Get the elapsed time as a TimeSpan value. ts.Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu.{3:00}". // Format and display the TimeSpan value. } } } void labelExit_Click( System::Object^ /*sender*/.Width .0). captureLap = false. } void labelTopRight_Click( Object^ /*sender*/.0).Milliseconds / 0.Screen::PrimaryScreen->WorkingArea.this->Height). } void labelBottomRight_Click( Object^ /*sender*/. } void labelBottomLeft_Click( Object^ /*sender*/. } 3/8 .Hours. System::EventArgs^ /*e*/ ) { // Close the form when the user clicks the close button.Minutes.Height . System::EventArgs^ /*e*/ ) { this->Location = Point(Screen::PrimaryScreen->WorkingArea. // then capture the current time for the lap time.Height .Seconds.001 ).Width this->Width. System::EventArgs^ /*e*/ ) { this->Location = Point(0. System::EventArgs^ /*e*/ ) { this->Location = Point(Screen::PrimaryScreen->WorkingArea.this->Width. System::EventArgs^ /*e*/ ) { this->Location = Point(0. // If the user has just clicked the "Lap" button.this->Height).

this->buttonLapReset = gcnew System::Windows::Forms::Button. 90 ). System::Windows::Forms::Label ^ labelBottomRight.Height . 100. System::EventArgs^ /*e*/ ) { // Shape the viewer form with rounded edges. 22 November 2009 12:51 . System::Windows::Forms::Timer^ timerMain.Width .Height . 0. 90 ). this->labelTime = gcnew System::Windows::Forms::Label. System::Windows::Forms::Label ^ labelTopRight. this->components = gcnew System::ComponentModel::Container.(Screen::PrimaryScreen->WorkingArea. } // Define various form elements. 90 ).this->Height) / 2). System::Windows::Forms::Button^ buttonLapReset. 180.Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu. graphicsPath->AddArc( 100. System::Windows::Forms::Button^ buttonStartStop.Terakhir Diperbaharui Minggu. System::Windows::Forms::Label ^ labelTopLeft. System::Windows::Forms::Label ^ labelExit. System::Windows::Forms::Label ^ labelLapPrompt. } void Form1_Load( Object^ /*sender*/. System::Windows::Forms::Label ^ labelBottomLeft. graphicsPath->AddArc( 0. 22 November 2009 12:54 void Form1_Click( Object^ /*sender*/. 0. this->labelExit = gcnew System::Windows::Forms::Label.this->Width) / 2. 100. 90 ).Width . 100. 100. 90. } void DrawForm() { // Shape the viewer form with rounded edges. 100.this->Width) / 2. 100. System::Windows::Forms::Label ^ labelTime.this->Height) / 2). 100. this->Location = Point((Screen::PrimaryScreen->WorkingArea. 0. System::EventArgs^ /*e*/ ) { this->Location = Point((Screen::PrimaryScreen->WorkingArea. void InitializeComponent() { this->SuspendLayout(). DrawForm(). 100. System::ComponentModel::Container^ components. this->Region = gcnew System::Drawing::Region( graphicsPath ). graphicsPath->AddArc( 100. GraphicsPath^ graphicsPath = gcnew GraphicsPath. 270. 100. graphicsPath->AddArc( 0.(Screen::PrimaryScreen->WorkingArea. System::Windows::Forms::Label ^ labelTimePrompt. System::Windows::Forms::Label ^ labelLap. 4/8 . 100.

this->buttonLapReset->Click += gcnew System::EventHandler( this. this->labelExit->Name = "labelExit".Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu. this->labelExit->ForeColor = System::Drawing::Color::Aqua. this->buttonLapReset->Name = "buttonLapReset". // labelExit this->labelExit->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D. this->labelTimePrompt = gcnew System::Windows::Forms::Label. // buttonLapReset this->buttonLapReset->Font = gcnew System::Drawing::Font( "Comic Sans MS".18. 20 ). 16 ). this->labelExit->TabIndex = 0. 56 ). this->labelTime->TabIndex = 1. 32 ). this->buttonLapReset->TabIndex = 4. 32 ). this->labelBottomRight = gcnew System::Windows::Forms::Label. this->timerMain->Interval = 1. this->labelExit->Click += gcnew System::EventHandler( this. // labelTime this->labelTime->Font = gcnew System::Drawing::Font( "Comic Sans MS".14. this->labelTime->Text = "00:00:00. this->labelBottomLeft = gcnew System::Windows::Forms::Label. this->labelExit->Text = "x". // timerMain this->timerMain->Enabled = true.System::Drawing::GraphicsUnit::Point ). &Form1::buttonLapReset_Click ). this->labelTopRight = gcnew System::Windows::Forms::Label. this->labelTime->Name = "labelTime".System::Drawing::FontStyle::Bold.25F. this->labelExit->Size = System::Drawing::Size( 20. this->labelLapPrompt = gcnew System::Windows::Forms::Label. this->buttonLapReset->Location = System::Drawing::Point( 104. this->labelExit->TextAlign = System::Drawing::ContentAlignment::BottomCenter.00". this->labelExit->Location = System::Drawing::Point( 160. this->buttonLapReset->Text = "Lap". this->labelTopLeft = gcnew System::Windows::Forms::Label. this->labelTime->Size = System::Drawing::Size( 208. this->labelLap = gcnew System::Windows::Forms::Label.System::Drawing::FontStyle::Bold. 22 November 2009 12:51 . 160 ). this->buttonStartStop = gcnew System::Windows::Forms::Button.Terakhir Diperbaharui Minggu. 22 November 2009 12:54 this->timerMain = gcnew System::Windows::Forms::Timer( this->components ). this->buttonLapReset->Size = System::Drawing::Size( 72.System::Drawing::GraphicsUnit::Point ). this->buttonLapReset->ForeColor = System::Drawing::Color::Yellow. this->labelTime->ForeColor = System::Drawing::Color::Yellow. &Form1::labelExit_Click ).0F. 5/8 . this->labelTime->Location = System::Drawing::Point(  -3.

this->labelLap->Size = System::Drawing::Size( 200. // labelLap this->labelLap->Font = gcnew System::Drawing::Font( "Comic Sans MS". this->labelLap->ForeColor = System::Drawing::Color::Yellow.15. this->labelLap->Name = "labelLap". 22 November 2009 12:51 . // labelLapPrompt this->labelLapPrompt->Font = gcnew System::Drawing::Font( "Comic Sans MS". 24 ). this->buttonStartStop->Font = gcnew System::Drawing::Font( "Comic Sans MS". 96 ).System::Drawing::GraphicsUnit::Point ). this->buttonStartStop->ForeColor = System::Drawing::Color::Yellow. 24 ).System::Drawing::GraphicsUnit::Point ).25F. this->buttonStartStop->TabIndex = 2. 6/8 . &Form1::timerMain_Tick ). // labelTimePrompt this->labelTimePrompt->Font = gcnew System::Drawing::Font( "Comic Sans MS". this->labelTimePrompt->TabIndex = 7. this->labelLapPrompt->Name = "labelLapPrompt". this->labelTimePrompt->ForeColor = System::Drawing::Color::Yellow. this->buttonStartStop->Size = System::Drawing::Size( 72. this->labelLapPrompt->ForeColor = System::Drawing::Color::Yellow.14.14.System::Drawing::GraphicsUnit::Point ).System::Drawing::FontStyle::Bold.System::Drawing::FontStyle::Regular. 22 November 2009 12:54 this->timerMain->Tick += gcnew System::EventHandler( this. 24 ). this->labelLapPrompt->Location = System::Drawing::Point( 8. 32 ).Terakhir Diperbaharui Minggu. 32 ). this->labelLap->Location = System::Drawing::Point( 0. &Form1::buttonStartStop_Click ).System::Drawing::FontStyle::Regular. this->buttonStartStop->Text = "Start".System::Drawing::FontStyle::Regular. this->labelLapPrompt->Size = System::Drawing::Size( 56. 160 ). this->labelLapPrompt->Visible = false. 120 ). this->buttonStartStop->Click += gcnew System::EventHandler( this. this->labelTimePrompt->Name = "labelTimePrompt". this->labelTimePrompt->Text = "Time".14. this->labelLap->Visible = false. this->labelLapPrompt->TabIndex = 6.25F. // buttonStartStop this->buttonStartStop->FlatStyle = System::Windows::Forms::FlatStyle::Flat. this->labelLap->TabIndex = 5.25F.75F. this->buttonStartStop->Name = "buttonStartStop". this->labelTimePrompt->Size = System::Drawing::Size( 88. this->buttonStartStop->Location = System::Drawing::Point( 24. this->labelLapPrompt->Text = "Lap Time". this->labelTimePrompt->Location = System::Drawing::Point( 0.System::Drawing::GraphicsUnit::Point ).Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu.

this->BackColor = System::Drawing::Color::Navy. // labelTopLeft this->labelTopLeft->BackColor = System::Drawing::Color::Black. this->labelBottomLeft->TabIndex = 8. this->labelTopRight->ForeColor = System::Drawing::Color::Black. 176 ). this->labelTopLeft->Location = System::Drawing::Point( 0. 16 ). this->labelTopRight->Name = "labelTopRight". this->labelTopLeft->TabIndex = 10. // Form1 this->AutoScaleBaseSize = System::Drawing::Size( 9. 22 ). this->labelTopLeft->Click += gcnew System::EventHandler( this.Terakhir Diperbaharui Minggu. // labelBottomRight this->labelBottomRight->BackColor = System::Drawing::Color::Black. this->labelTopRight->Click += gcnew System::EventHandler( this. &Form1::labelBottomLeft_Click ). this->labelBottomRight->Size = System::Drawing::Size( 16. 8 ). 16 ). 176 ). 16 ). this->labelTopRight->Size = System::Drawing::Size( 16. this->labelBottomRight->ForeColor = System::Drawing::Color::Black. this->Controls->Add( this->labelTopRight ).Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu. 7/8 . this->Controls->Add( this->labelBottomRight ). this->labelBottomRight->TabIndex = 9. this->labelTopLeft->Size = System::Drawing::Size( 16. 22 November 2009 12:54 // labelBottomLeft this->labelBottomLeft->BackColor = System::Drawing::Color::Black. // labelTopRight this->labelTopRight->BackColor = System::Drawing::Color::Black. this->labelBottomLeft->Location = System::Drawing::Point( 0. this->labelBottomLeft->ForeColor = System::Drawing::Color::Black. this->labelBottomLeft->Name = "labelBottomLeft". this->ClientSize = System::Drawing::Size( 200. this->Controls->Add( this->labelTopLeft ). this->labelBottomLeft->Size = System::Drawing::Size( 16. this->labelTopRight->TabIndex = 11. &Form1::labelTopLeft_Click ). this->labelBottomRight->Location = System::Drawing::Point( 184. 8 ). this->labelTopLeft->Name = "labelTopLeft". 16 ). this->labelBottomRight->Name = "labelBottomRight". &Form1::labelBottomRight_Click ). 200 ). this->labelBottomLeft->Click += gcnew System::EventHandler( this. &Form1::labelTopRight_Click ). 22 November 2009 12:51 . this->labelBottomRight->Click += gcnew System::EventHandler( this. this->labelTopLeft->ForeColor = System::Drawing::Color::Black. this->labelTopRight->Location = System::Drawing::Point( 184.

8/8 . this->Controls->Add( this->labelLapPrompt ). 22 November 2009 12:51 . this->Controls->Add( this->buttonStartStop ).Terakhir Diperbaharui Minggu.14. this->Controls->Add( this->labelLap ). this->Name = "Form1". this->Controls->Add( this->labelTime ). this->TopMost = true.System::Drawing::GraphicsUnit::Point ). this->Controls->Add( this->labelTimePrompt ). this->Text = "StopWatch Sample". this->ResumeLayout( false ). this->Font = gcnew System::Drawing::Font( "Microsoft Sans Serif". this->Controls->Add( this->labelExit ). &Form1::Form1_Load ). this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None. } }. this->Load += gcnew System::EventHandler( this.25F.Program Stopwatch Hingga Microsecond Ditulis oleh Administrator Minggu.System::Drawing::FontStyle::Regular. this->Controls->Add( this->buttonLapReset ). 22 November 2009 12:54 this->Controls->Add( this->labelBottomLeft ).