Exemple #1
0
        private void PlayButton_Click(object sender, EventArgs e)
        {
            // The stopwatch logic can be in one of three possible
            // states, off, stopwatch only, and on.  The play button's
            // only functionality is to set the stopwatch logic to on.
            // The play button will only function in the off and
            // stopwatch only mode, with it's purpose to set the on
            // mode.  If this event can be raised, the mode is either
            // off or stopwatch only.  If the stopwatch object is not
            // running, it's in the off mode, thus the stopwatch
            // object must be started.  The timer object must be
            // started.  With both running, the stopwatch logic is in
            // on mode, in which the play button must not be enabled,
            // and the stop button (available in stopwatch and on mode,
            // prohibited in off mode) must be enabled.  The pause
            // button is always enabled, and does not need to be
            // changed.

            // Switching to on mode, play has no defined behavior
            PlayButton.Enabled = false;
            // Switching of on mode, stop has a defined behavior
            StopButton.Enabled = true;

            // Even if in on mode, starting a stopwatch that's already
            // started does not affect the stopwatch or it's current
            // elapsed time.
            stopwatch.Start();
            StopwatchUpdateTimer.Start();
            timerUpdatesUI = true;
        }
Exemple #2
0
        private void StopButton_Click(object sender, EventArgs e)
        {
            // The stopwatch logic can be in one of three states,
            // off (both stopwatch and timer off), stopwatch only
            // (stopwatch on, timer off), and on (both stopwatch
            // and timer on). The purpose of the stop button is to move
            // on mode or stopwatch only mode to the off mode. In the
            // off mode, stop is undefined and must be disabled,
            // while play is defined and must be enabled.  Pause is
            // always defined, always enabled, and need not be changed.

            StopButton.Enabled = false;
            PlayButton.Enabled = true;

            stopwatch.Stop();
            StopwatchUpdateTimer.Stop();
            timerUpdatesUI = false;
        }