Esta documentación está archivada y no tiene mantenimiento.

Stopwatch (Clase)

Nota: esta clase es nueva en la versión 2.0 de .NET Framework.

Proporciona un conjunto de métodos y propiedades que se puede utilizar para medir el tiempo transcurrido con precisión.

Espacio de nombres: System.Diagnostics
Ensamblado: System (en system.dll)

'Declaración
Public Class Stopwatch
'Uso
Dim instance As Stopwatch

public class Stopwatch
public class Stopwatch

Una instancia de Stopwatch puede medir el tiempo transcurrido para un intervalo o el total de tiempo transcurrido entre varios intervalos. En un escenario de Stopwatch habitual, se llama al método Start, en otro momento se llama al método Stop y, por último, se comprueba el tiempo transcurrido mediante la propiedad Elapsed.

Una instancia de Stopwatch se está ejecutando o está detenida; utilice IsRunning para determinar el estado actual de Stopwatch. Utilice Start para empezar a medir el tiempo transcurrido; utilice Stop para detener la medida del tiempo transcurrido. Consulte el valor de tiempo transcurrido a través de las propiedades Elapsed, ElapsedMilliseconds o ElapsedTicks. Puede consultar las propiedades de tiempo transcurrido mientras la instancia se está ejecutando o mientras está detenida. Las propiedades de tiempo transcurrido aumentan continuamente mientras se ejecuta Stopwatch; permanecen constantes cuando la instancia está detenida.

De manera predeterminada, el valor de tiempo transcurrido de una instancia de Stopwatch es igual al total de todos los intervalos de tiempo medidos. Cada llamada a Start inicia la cuenta del tiempo transcurrido acumulado; cada llamada a Stop finaliza la medición del intervalo actual y bloquea el valor de tiempo transcurrido acumulado. Utilice el método Reset para borrar el tiempo transcurrido acumulado en una instancia de Stopwatch existente.

Stopwatch mide el tiempo transcurrido contando pasos del temporizador en el mecanismo de temporización subyacente. Si el hardware instalado y el sistema operativo admiten un contador de rendimiento de alta resolución, la clase Stopwatch utiliza ese contador para medir el tiempo transcurrido. De lo contrario, la clase Stopwatch utiliza el temporizador del sistema para medir el tiempo transcurrido. Utilice los campos Frequency y IsHighResolution para determinar la precisión y la resolución de la implementación de control de tiempo de Stopwatch.

La clase Stopwatch ayuda en la manipulación de contadores de rendimiento relacionados con el control de tiempo dentro del código administrado. Específicamente, el campo Frequency y el método GetTimestamp pueden utilizarse en lugar de QueryPerformanceFrequency y QueryPerformanceCounter de las API Win32 no administradas.

NotaNota

En un equipo con varios procesadores, no importa en qué procesador se ejecuta el subproceso. Sin embargo, debido a errores del BIOS o de la Capa de abstracción de hardware (HAL), se pueden obtener diferentes resultados de control de tiempo en diferentes procesadores. Para especificar la afinidad del procesador para un subproceso, utilice el método ProcessThread.ProcessorAffinity.

En el ejemplo siguiente se utiliza la clase Stopwatch para implementar las operaciones de cronómetro de una aplicación de Windows Forms.

Imports System
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class formMain
    Inherits System.Windows.Forms.Form

    Dim stopWatch As StopWatch
    Dim captureLap As Boolean

    Public Sub New()

        MyBase.New()
        stopwatch = New StopWatch()
        captureLap = False
        InitializeComponent()

    End Sub

    ' Override dispose method to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Shared Sub Main()
        Application.Run(New formMain)
    End Sub

    ' Define event handlers for various form events.

    Private Sub buttonStartStop_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles buttonStartStop.Click

        ' 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 Then

            ' Stop the timer; show the start and reset buttons.
            stopWatch.Stop()
            buttonStartStop.Text = "Start"
            buttonLapReset.Text = "Reset"
        Else
            ' Start the timer; show the stop and lap buttons.
            stopWatch.Start()
            buttonStartStop.Text = "Stop"
            buttonLapReset.Text = "Lap"
            labelLap.Visible = False
            labelLapPrompt.Visible = False
        End If
    End Sub

    Private Sub buttonLapReset_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles buttonLapReset.Click

        ' When the timer is stopped, this button event resets
        ' the timer.  When the timer is running, this button  
        ' event captures a lap time.
        If buttonLapReset.Text = "Lap" Then
            If stopWatch.IsRunning Then

                ' Set the object state so that the next
                ' timer tick will display the lap time value.

                captureLap = True
                labelLap.Visible = True
                labelLapPrompt.Visible = True
            End If
        Else
            ' Reset the stopwatch and the displayed timer value.
            labelTime.Text = "00:00:00.00"
            buttonLapReset.Text = "Lap"
            stopWatch.Reset()
            labelLap.Visible = False
            labelLapPrompt.Visible = False
        End If
    End Sub

    Private Sub timerMain_Tick(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles timerMain.Tick

        ' When the timer is running, update the displayed timer 
        ' value for each tick event.

        If stopWatch.IsRunning Then
            ' Get the elapsed time as a TimeSpan value.
            Dim ts As TimeSpan = stopWatch.Elapsed

            ' Format and display the TimeSpan value.
            labelTime.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
                ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds/10)

            ' If the user has just clicked the "Lap" button,
            ' then capture the current time for the lap time.
            If captureLap Then
                labelLap.Text = labelTime.Text
                captureLap = False
            End If
        End If
    End Sub


    Private Sub labelExit_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles labelExit.Click

        ' Close the form when the user clicks the close button.
        Me.Close()
    End Sub

    Private Sub labelTopLeft_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles labelTopLeft.Click

        Me.Location = New Point(0, 0)
    End Sub

    Private Sub labelBottomLeft_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles labelBottomLeft.Click

        Me.Location = New Point(0, Screen.PrimaryScreen.WorkingArea.Height - Me.Height)
    End Sub

    Private Sub labelTopRight_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles labelTopRight.Click

        Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, 0)
    End Sub

    Private Sub labelBottomRight_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles labelBottomRight.Click

        Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, Screen.PrimaryScreen.WorkingArea.Height - Me.Height)
    End Sub

    Private Sub formMain_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles MyBase.Click

        Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2)
    End Sub

    Private Sub formMain_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load

        DrawForm()
        Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2)
    End Sub

    Private Sub DrawForm()

        ' Shape the viewer form with rounded edges.
        Dim GraphicsPath As New Drawing2D.GraphicsPath

        GraphicsPath.AddArc(0, 0, 100, 100, 180, 90)
        GraphicsPath.AddArc(100, 0, 100, 100, 270, 90)
        GraphicsPath.AddArc(100, 100, 100, 100, 0, 90)
        GraphicsPath.AddArc(0, 100, 100, 100, 90, 90)

        Me.Region = New Region(GraphicsPath)
    End Sub

    Private components As System.ComponentModel.IContainer

    Private WithEvents labelExit As System.Windows.Forms.Label
    Private WithEvents labelTime As System.Windows.Forms.Label
    Private WithEvents timerMain As System.Windows.Forms.Timer
    Private WithEvents buttonLapReset As System.Windows.Forms.Button
    Private WithEvents buttonStartStop As System.Windows.Forms.Button
    Private WithEvents labelLapPrompt As System.Windows.Forms.Label
    Private WithEvents labelTimePrompt As System.Windows.Forms.Label
    Private WithEvents labelLap As System.Windows.Forms.Label
    Private WithEvents labelBottomLeft As System.Windows.Forms.Label
    Private WithEvents labelBottomRight As System.Windows.Forms.Label
    Private WithEvents labelTopLeft As System.Windows.Forms.Label
    Private WithEvents labelTopRight As System.Windows.Forms.Label

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.labelExit = New System.Windows.Forms.Label
        Me.labelTime = New System.Windows.Forms.Label
        Me.buttonLapReset = New System.Windows.Forms.Button
        Me.timerMain = New System.Windows.Forms.Timer(Me.components)
        Me.labelLap = New System.Windows.Forms.Label
        Me.buttonStartStop = New System.Windows.Forms.Button
        Me.labelLapPrompt = New System.Windows.Forms.Label
        Me.labelTimePrompt = New System.Windows.Forms.Label
        Me.labelBottomLeft = New System.Windows.Forms.Label
        Me.labelBottomRight = New System.Windows.Forms.Label
        Me.labelTopLeft = New System.Windows.Forms.Label
        Me.labelTopRight = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'labelExit
        '
        Me.labelExit.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.labelExit.ForeColor = System.Drawing.Color.Aqua
        Me.labelExit.Location = New System.Drawing.Point(160, 16)
        Me.labelExit.Name = "labelExit"
        Me.labelExit.Size = New System.Drawing.Size(20, 20)
        Me.labelExit.TabIndex = 0
        Me.labelExit.Text = "x"
        Me.labelExit.TextAlign = System.Drawing.ContentAlignment.BottomCenter
        '
        'labelTime
        '
        Me.labelTime.Font = New System.Drawing.Font("Comic Sans MS", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.labelTime.ForeColor = System.Drawing.Color.Yellow
        Me.labelTime.Location = New System.Drawing.Point(-3, 56)
        Me.labelTime.Name = "labelTime"
        Me.labelTime.Size = New System.Drawing.Size(208, 32)
        Me.labelTime.TabIndex = 1
        Me.labelTime.Text = "00:00:00.00"
        '
        'buttonLapReset
        '
        Me.buttonLapReset.Font = New System.Drawing.Font("Comic Sans MS", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.buttonLapReset.ForeColor = System.Drawing.Color.Yellow
        Me.buttonLapReset.Location = New System.Drawing.Point(104, 160)
        Me.buttonLapReset.Name = "buttonLapReset"
        Me.buttonLapReset.Size = New System.Drawing.Size(72, 32)
        Me.buttonLapReset.TabIndex = 4
        Me.buttonLapReset.Text = "Lap"
        '
        'timerMain
        '
        Me.timerMain.Enabled = True
        Me.timerMain.Interval = 50
        '
        'labelLap
        '
        Me.labelLap.Font = New System.Drawing.Font("Comic Sans MS", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.labelLap.ForeColor = System.Drawing.Color.Yellow
        Me.labelLap.Location = New System.Drawing.Point(0, 120)
        Me.labelLap.Name = "labelLap"
        Me.labelLap.Size = New System.Drawing.Size(200, 32)
        Me.labelLap.TabIndex = 5
        Me.labelLap.Visible = False
        '
        'buttonStartStop
        '
        Me.buttonStartStop.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.buttonStartStop.Font = New System.Drawing.Font("Comic Sans MS", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.buttonStartStop.ForeColor = System.Drawing.Color.Yellow
        Me.buttonStartStop.Location = New System.Drawing.Point(24, 160)
        Me.buttonStartStop.Name = "buttonStartStop"
        Me.buttonStartStop.Size = New System.Drawing.Size(72, 32)
        Me.buttonStartStop.TabIndex = 2
        Me.buttonStartStop.Text = "Start"
        '
        'labelLapPrompt
        '
        Me.labelLapPrompt.Font = New System.Drawing.Font("Comic Sans MS", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.labelLapPrompt.ForeColor = System.Drawing.Color.Yellow
        Me.labelLapPrompt.Location = New System.Drawing.Point(8, 96)
        Me.labelLapPrompt.Name = "labelLapPrompt"
        Me.labelLapPrompt.Size = New System.Drawing.Size(96, 24)
        Me.labelLapPrompt.TabIndex = 6
        Me.labelLapPrompt.Text = "Lap Time"
        Me.labelLapPrompt.Visible = False
        '
        'labelTimePrompt
        '
        Me.labelTimePrompt.Font = New System.Drawing.Font("Comic Sans MS", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.labelTimePrompt.ForeColor = System.Drawing.Color.Yellow
        Me.labelTimePrompt.Location = New System.Drawing.Point(0, 24)
        Me.labelTimePrompt.Name = "labelTimePrompt"
        Me.labelTimePrompt.Size = New System.Drawing.Size(88, 24)
        Me.labelTimePrompt.TabIndex = 7
        Me.labelTimePrompt.Text = "Time"
        '
        'labelBottomLeft
        '
        Me.labelBottomLeft.BackColor = System.Drawing.Color.Black
        Me.labelBottomLeft.ForeColor = System.Drawing.Color.Black
        Me.labelBottomLeft.Location = New System.Drawing.Point(0, 176)
        Me.labelBottomLeft.Name = "labelBottomLeft"
        Me.labelBottomLeft.Size = New System.Drawing.Size(16, 16)
        Me.labelBottomLeft.TabIndex = 8
        '
        'labelBottomRight
        '
        Me.labelBottomRight.BackColor = System.Drawing.Color.Black
        Me.labelBottomRight.ForeColor = System.Drawing.Color.Black
        Me.labelBottomRight.Location = New System.Drawing.Point(184, 176)
        Me.labelBottomRight.Name = "labelBottomRight"
        Me.labelBottomRight.Size = New System.Drawing.Size(16, 16)
        Me.labelBottomRight.TabIndex = 9
        '
        'labelTopLeft
        '
        Me.labelTopLeft.BackColor = System.Drawing.Color.Black
        Me.labelTopLeft.ForeColor = System.Drawing.Color.Black
        Me.labelTopLeft.Location = New System.Drawing.Point(0, 8)
        Me.labelTopLeft.Name = "labelTopLeft"
        Me.labelTopLeft.Size = New System.Drawing.Size(16, 16)
        Me.labelTopLeft.TabIndex = 10
        '
        'labelTopRight
        '
        Me.labelTopRight.BackColor = System.Drawing.Color.Black
        Me.labelTopRight.ForeColor = System.Drawing.Color.Black
        Me.labelTopRight.Location = New System.Drawing.Point(184, 8)
        Me.labelTopRight.Name = "labelTopRight"
        Me.labelTopRight.Size = New System.Drawing.Size(16, 16)
        Me.labelTopRight.TabIndex = 11
        '
        'formMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(9, 22)
        Me.BackColor = System.Drawing.Color.Navy
        Me.ClientSize = New System.Drawing.Size(200, 200)
        Me.Controls.Add(Me.labelTopRight)
        Me.Controls.Add(Me.labelTopLeft)
        Me.Controls.Add(Me.labelBottomRight)
        Me.Controls.Add(Me.labelBottomLeft)
        Me.Controls.Add(Me.labelTimePrompt)
        Me.Controls.Add(Me.labelLapPrompt)
        Me.Controls.Add(Me.labelLap)
        Me.Controls.Add(Me.buttonLapReset)
        Me.Controls.Add(Me.buttonStartStop)
        Me.Controls.Add(Me.labelTime)
        Me.Controls.Add(Me.labelExit)
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "formMain"
        Me.Text = "StopWatch Sample"
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub

End Class

import System.*;
import System.Diagnostics.*;
import System.Windows.Forms.*;
import System.Drawing.*;
import System.Drawing.Drawing2D.*;

public class FormMain extends System.Windows.Forms.Form
{
    private Stopwatch stopWatch;
    private Boolean captureLap;

    public FormMain()
    {
        stopWatch = new Stopwatch();
        captureLap = new Boolean(false);

        InitializeComponent();
    } //FormMain

    protected void Dispose(boolean disposing)
    {
        super.Dispose(disposing);
    } //Dispose

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new FormMain());
    } //main

    // Define event handlers for various form events.
    private void buttonStartStop_Click(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.get_IsRunning()) {
            // Stop the timer; show the start and reset buttons.
            stopWatch.Stop();
            buttonStartStop.set_Text("Start");
            buttonLapReset.set_Text("Reset");
        }
        else {
            // Start the timer; show the stop and lap buttons.
            stopWatch.Start();
            buttonStartStop.set_Text("Stop");
            buttonLapReset.set_Text("Lap");
            labelLap.set_Visible(false);
            labelLapPrompt.set_Visible(false);
        }
    } //buttonStartStop_Click
    
    private void buttonLapReset_Click(Object sender, System.EventArgs e)
    {
        // When the timer is stopped, this button event resets
        // the timer.  When the timer is running, this button  
        // event captures a lap time.
        if (buttonLapReset.get_Text().Equals("Lap")) {
            if (stopWatch.get_IsRunning()) {
                // Set the object state so that the next
                // timer tick will display the lap time value.
                captureLap = new Boolean(true);
                labelLap.set_Visible(true);
                labelLapPrompt.set_Visible(true);
            }
        }
        else {
            // Reset the stopwatch and the displayed timer value.
            labelLap.set_Visible(false);
            labelLapPrompt.set_Visible(false);
            labelTime.set_Text("00:00:00.00");
            buttonLapReset.set_Text("Lap");
            stopWatch.Reset();
        } 
    } //buttonLapReset_Click

    private void timerMain_Tick(Object sender, System.EventArgs e)
    {
        // When the timer is running, update the displayed timer 
        // value for each tick event.
        if (stopWatch.get_IsRunning()) {
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.get_Elapsed();
            // Format and display the TimeSpan value.
            labelTime.set_Text(((System.Int32)ts.get_Hours()).ToString("00") 
                + ":" + ((System.Int32)ts.get_Minutes()).ToString("00") 
                + ":" + ((System.Int32)ts.get_Seconds()).ToString("00") 
                + "." + ((System.Int32)(ts.get_Milliseconds() / 10)).
                ToString("00"));
            // If the user has just clicked the "Lap" button,
            // then capture the current time for the lap time.
            if (System.Convert.ToBoolean(captureLap)) {
                labelLap.set_Text(labelTime.get_Text());
                captureLap = new Boolean(false);
            }
        }
    } //timerMain_Tick

    private void labelExit_Click(Object sender, System.EventArgs e)
    {
        // Close the form when the user clicks the close button.
        this.Close();
    } //labelExit_Click

    private void labelTopLeft_Click(Object sender, System.EventArgs e)
    {
        this.set_Location(new Point(0, 0));
    } //labelTopLeft_Click

    private void labelBottomLeft_Click(Object sender, System.EventArgs e)
    {
        this.set_Location(new Point(0, Screen.get_PrimaryScreen().
            get_WorkingArea().get_Height() - this.get_Height()));
    } //labelBottomLeft_Click

    private void labelTopRight_Click(Object sender, System.EventArgs e)
    {
        this.set_Location(new Point(Screen.get_PrimaryScreen().
            get_WorkingArea().get_Width() - this.get_Width(), 0));
    } //labelTopRight_Click

    private void labelBottomRight_Click(Object sender, System.EventArgs e)
    {
        this.set_Location(new Point(Screen.get_PrimaryScreen().
            get_WorkingArea().get_Width() - this.get_Width(), 
            Screen.get_PrimaryScreen().get_WorkingArea().get_Height() 
            - this.get_Height()));
    } //labelBottomRight_Click

    private void FormMain_Click(Object sender, System.EventArgs e)
    {
        this.set_Location(new Point((Screen.get_PrimaryScreen().
            get_WorkingArea().get_Width() - this.get_Width()) / 2, 
            (Screen.get_PrimaryScreen().get_WorkingArea().get_Height() 
            - this.get_Height()) / 2));
    } //FormMain_Click

    private void FormMain_Load(Object sender, System.EventArgs e)
    {
        // Shape the viewer form with rounded edges.
        DrawForm();
        this.set_Location(new Point((Screen.get_PrimaryScreen().
            get_WorkingArea().get_Width() - this.get_Width()) / 2, 
            (Screen.get_PrimaryScreen().get_WorkingArea().get_Height() 
            - this.get_Height()) / 2));
    } //FormMain_Load

    private void DrawForm()
    {
        // Shape the viewer form with rounded edges.
        GraphicsPath graphicsPath = new GraphicsPath();

        graphicsPath.AddArc(0, 0, 100, 100, 180, 90);
        graphicsPath.AddArc(100, 0, 100, 100, 270, 90);
        graphicsPath.AddArc(100, 100, 100, 100, 0, 90);
        graphicsPath.AddArc(0, 100, 100, 100, 90, 90);

        this.set_Region(new Region(graphicsPath));
    } //DrawForm

    // Define various form elements.
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.Label labelExit;
    private System.Windows.Forms.Label labelTime;
    private System.Windows.Forms.Timer timerMain;
    private System.Windows.Forms.Button buttonLapReset;
    private System.Windows.Forms.Button buttonStartStop;
    private System.Windows.Forms.Label labelLapPrompt;
    private System.Windows.Forms.Label labelTimePrompt;
    private System.Windows.Forms.Label labelLap;
    private System.Windows.Forms.Label labelBottomLeft;
    private System.Windows.Forms.Label labelBottomRight;
    private System.Windows.Forms.Label labelTopLeft;
    private System.Windows.Forms.Label labelTopRight;

    private void InitializeComponent()
    {
        this.SuspendLayout();

        this.components = new System.ComponentModel.Container();
        this.labelExit = new System.Windows.Forms.Label();
        this.labelTime = new System.Windows.Forms.Label();
        this.buttonLapReset = new System.Windows.Forms.Button();
        this.timerMain = new System.Windows.Forms.Timer(this.components);
        this.labelLap = new System.Windows.Forms.Label();
        this.buttonStartStop = new System.Windows.Forms.Button();
        this.labelLapPrompt = new System.Windows.Forms.Label();
        this.labelTimePrompt = new System.Windows.Forms.Label();
        this.labelBottomLeft = new System.Windows.Forms.Label();
        this.labelBottomRight = new System.Windows.Forms.Label();
        this.labelTopLeft = new System.Windows.Forms.Label();
        this.labelTopRight = new System.Windows.Forms.Label();
        // labelExit
        this.labelExit.set_BorderStyle(
            System.Windows.Forms.BorderStyle.Fixed3D);
        this.labelExit.set_ForeColor(System.Drawing.Color.get_Aqua());
        this.labelExit.set_Location(new System.Drawing.Point(160, 16));
        this.labelExit.set_Name("labelExit");
        this.labelExit.set_Size(new System.Drawing.Size(20, 20));
        this.labelExit.set_TabIndex(0);
        this.labelExit.set_Text("x");
        this.labelExit.set_TextAlign(
            System.Drawing.ContentAlignment.BottomCenter);
        this.labelExit.add_Click(new System.EventHandler(this.labelExit_Click));
        // labelTime
        this.labelTime.set_Font(new System.Drawing.Font("Comic Sans MS", 18, 
            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point));
        this.labelTime.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.labelTime.set_Location(new System.Drawing.Point(-3, 56));
        this.labelTime.set_Name("labelTime");
        this.labelTime.set_Size(new System.Drawing.Size(208, 32));
        this.labelTime.set_TabIndex(1);
        this.labelTime.set_Text("00:00:00.00");
        // buttonLapReset
        this.buttonLapReset.set_Font(new System.Drawing.Font("Comic Sans MS", 
            14.25f, System.Drawing.FontStyle.Bold, 
            System.Drawing.GraphicsUnit.Point));
        this.buttonLapReset.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.buttonLapReset.set_Location(new System.Drawing.Point(104, 160));
        this.buttonLapReset.set_Name("buttonLapReset");
        this.buttonLapReset.set_Size(new System.Drawing.Size(72, 32));
        this.buttonLapReset.set_TabIndex(4);
        this.buttonLapReset.set_Text("Lap");
        this.buttonLapReset.add_Click(new System.EventHandler(
            this.buttonLapReset_Click));
        // timerMain
        this.timerMain.set_Enabled(true);
        this.timerMain.set_Interval(50);
        this.timerMain.add_Tick(new System.EventHandler(this.timerMain_Tick));
        // labelLap
        this.labelLap.set_Font(new System.Drawing.Font("Comic Sans MS", 
            (float)14.25, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point));
        this.labelLap.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.labelLap.set_Location(new System.Drawing.Point(0, 120));
        this.labelLap.set_Name("labelLap");
        this.labelLap.set_Size(new System.Drawing.Size(200, 32));
        this.labelLap.set_TabIndex(5);
        this.labelLap.set_Visible(false);
        // buttonStartStop
        this.buttonStartStop.set_FlatStyle(System.Windows.Forms.FlatStyle.Flat);
        this.buttonStartStop.set_Font(new System.Drawing.Font("Comic Sans MS",
            (float)14.25, System.Drawing.FontStyle.Bold, 
            System.Drawing.GraphicsUnit.Point));
        this.buttonStartStop.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.buttonStartStop.set_Location(new System.Drawing.Point(24, 160));
        this.buttonStartStop.set_Name("buttonStartStop");
        this.buttonStartStop.set_Size(new System.Drawing.Size(72, 32));
        this.buttonStartStop.set_TabIndex(2);
        this.buttonStartStop.set_Text("Start");
        this.buttonStartStop.add_Click(new System.EventHandler(
            this.buttonStartStop_Click));
        // labelLapPrompt
        this.labelLapPrompt.set_Font(new System.Drawing.Font("Comic Sans MS", 
            (float)14.25, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point));
        this.labelLapPrompt.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.labelLapPrompt.set_Location(new System.Drawing.Point(8, 96));
        this.labelLapPrompt.set_Name("labelLapPrompt");
        this.labelLapPrompt.set_Size(new System.Drawing.Size(56, 24));
        this.labelLapPrompt.set_TabIndex(6);
        this.labelLapPrompt.set_Text("Lap Time");
        this.labelLapPrompt.set_Visible(false);
        // labelTimePrompt
        this.labelTimePrompt.set_Font(new System.Drawing.Font("Comic Sans MS", 
            (float)15.75, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point));
        this.labelTimePrompt.set_ForeColor(System.Drawing.Color.get_Yellow());
        this.labelTimePrompt.set_Location(new System.Drawing.Point(0, 24));
        this.labelTimePrompt.set_Name("labelTimePrompt");
        this.labelTimePrompt.set_Size(new System.Drawing.Size(88, 24));
        this.labelTimePrompt.set_TabIndex(7);
        this.labelTimePrompt.set_Text("Time");
        // labelBottomLeft
        this.labelBottomLeft.set_BackColor(System.Drawing.Color.get_Black());
        this.labelBottomLeft.set_ForeColor(System.Drawing.Color.get_Black());
        this.labelBottomLeft.set_Location(new System.Drawing.Point(0, 176));
        this.labelBottomLeft.set_Name("labelBottomLeft");
        this.labelBottomLeft.set_Size(new System.Drawing.Size(16, 16));
        this.labelBottomLeft.set_TabIndex(8);
        this.labelBottomLeft.add_Click(new System.EventHandler(
            this.labelBottomLeft_Click));
        // labelBottomRight
        this.labelBottomRight.set_BackColor(System.Drawing.Color.get_Black());
        this.labelBottomRight.set_ForeColor(System.Drawing.Color.get_Black());
        this.labelBottomRight.set_Location(new System.Drawing.Point(184, 176));
        this.labelBottomRight.set_Name("labelBottomRight");
        this.labelBottomRight.set_Size(new System.Drawing.Size(16, 16));
        this.labelBottomRight.set_TabIndex(9);
        this.labelBottomRight.add_Click(new System.EventHandler(
            this.labelBottomRight_Click));
        // labelTopLeft
        this.labelTopLeft.set_BackColor(System.Drawing.Color.get_Black());
        this.labelTopLeft.set_ForeColor(System.Drawing.Color.get_Black());
        this.labelTopLeft.set_Location(new System.Drawing.Point(0, 8));
        this.labelTopLeft.set_Name("labelTopLeft");
        this.labelTopLeft.set_Size(new System.Drawing.Size(16, 16));
        this.labelTopLeft.set_TabIndex(10);
        this.labelTopLeft.add_Click(new System.EventHandler(
            this.labelTopLeft_Click));
        // labelTopRight
        this.labelTopRight.set_BackColor(System.Drawing.Color.get_Black());
        this.labelTopRight.set_ForeColor(System.Drawing.Color.get_Black());
        this.labelTopRight.set_Location(new System.Drawing.Point(184, 8));
        this.labelTopRight.set_Name("labelTopRight");
        this.labelTopRight.set_Size(new System.Drawing.Size(16, 16));
        this.labelTopRight.set_TabIndex(11);
        this.labelTopRight.add_Click(new System.EventHandler(
            this.labelTopRight_Click));
        // FormMain
        this.set_AutoScaleBaseSize(new System.Drawing.Size(9, 22));
        this.set_BackColor(System.Drawing.Color.get_Navy());
        this.set_ClientSize(new System.Drawing.Size(200, 200));
        this.get_Controls().Add(this.labelTopRight);
        this.get_Controls().Add(this.labelTopLeft);
        this.get_Controls().Add(this.labelBottomRight);
        this.get_Controls().Add(this.labelBottomLeft);
        this.get_Controls().Add(this.labelTimePrompt);
        this.get_Controls().Add(this.labelLapPrompt);
        this.get_Controls().Add(this.labelLap);
        this.get_Controls().Add(this.buttonLapReset);
        this.get_Controls().Add(this.buttonStartStop);
        this.get_Controls().Add(this.labelTime);
        this.get_Controls().Add(this.labelExit);
        this.set_Font(new System.Drawing.Font("Microsoft Sans Serif", 
            (float)14.25, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point));
        this.set_FormBorderStyle(System.Windows.Forms.FormBorderStyle.None);
        this.set_Name("FormMain");
        this.set_Text("StopWatch Sample");
        this.set_TopMost(true);
        this.add_Load(new System.EventHandler(this.FormMain_Load));

        this.ResumeLayout(false);
    } //InitializeComponent
} //FormMain

System.Object
  System.Diagnostics.Stopwatch

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0
Mostrar: