private void Tick(object sender, EventArgs e)
        {
            if (HasFinished)
            {
                throw new Exception();
            }

            // update Time
            var current = OriginalTime.Subtract(_stopwatch.Elapsed);

            if (current.CompareTo(TimeSpan.Zero) < 0)
            {
                current = TimeSpan.Zero;
            }
            CurrentTime = current;
            HasFinished = CurrentTime.TotalSeconds <= 0;

            //ProgressBarValue = CurrentTime.TotalSeconds; // bug value not visible on view after reset
            ProgressBar.Value = CurrentTime.TotalSeconds;

            // update background color
            if (HasFinished)
            {
                FillColor       = Common.GrayColorBrush;
                ForegroundColor = Common.DarkGrayColorBrush;
                if (OnFinished != null)
                {
                    OnFinished(this, null);
                }
            }
        }
示例#2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            CurrentTime = CurrentTime.Subtract(Timer.Interval);

            TimerTextBox.Text = CurrentTime.ToString();

            if (CurrentTime.Equals(TimeSpan.Zero))
            {
                Timer.Stop();

                this.Activate();

                String currentTimeString = DateTime.Now.ToString("HH:mm:ss");

                this.NotifyIcon.ShowBalloonTip(5000, "Time is up!", $"@ {currentTimeString}", WinForms.ToolTipIcon.Info);

                MessageBox.Show(this, $"Time is up!{Environment.NewLine}@ {currentTimeString}",
                                this.Title, MessageBoxButton.OK, MessageBoxImage.Information);

                TimerTextBox.Text = OriginalTime.ToString();

                TimerButtonImage.Source = this.FindResource("TimerStartIcon") as DrawingImage;

                TimerTextBox.IsReadOnly = Timer.IsEnabled;
                TaskTextBox.IsReadOnly  = Timer.IsEnabled;
            }
        }