⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledclockctrl.cs

📁 基于wince的LED时钟 c#实现,达到和电子表一样的效果
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    AlarmTimes.RemoveAt(i);
                    RaiseAlarm();
                }
            }
            switch (clockType)
            {
                case ClockType.DigitalClock:
                    if (clockDisplayFormat == ClockFormat.TwelveHourFormat)
                    {
                        hour = dt.Hour % 12;
                        if (hour == 0) hour = 12;
                    }
                    switch (clockDisplayFormat)
                    {
                        case ClockFormat.TwentyFourHourFormat:
                            break;
                        case ClockFormat.TwelveHourFormat:
                            am_pm = (dt.Hour / 12 > 0) ? 'P' : 'A';
                            break;
                    }
                    break;
                case ClockType.CountDown:
                    ts = countDownTo.Subtract(dt);
                    if (ts < TimeSpan.Zero)
                    {
                        clockType = ClockType.DigitalClock;
                        ts = TimeSpan.Zero;
                        if (CountDownDone != null)
                            CountDownDone();
                    }
                    break;
                case ClockType.StopWatch:
                    ts = dt.Subtract(this.stopwatchBegin);
                    break;
                case ClockType.Freeze:
                    break;
            }
            if (clockType != ClockType.DigitalClock &&
                clockType != ClockType.Freeze) // ts used for stopwatch or countdown
            {
                hour = ts.Hours;
                min = ts.Minutes;
                sec = ts.Seconds;
                ms = ts.Milliseconds;
            }
            DigitDisplay[0].Draw(hour / 10, g);
            DigitDisplay[1].Draw(hour % 10, g);
            DigitDisplay[2].Draw(min / 10, g);
            DigitDisplay[3].Draw(min % 10, g);
            DigitDisplay[4].Draw(sec / 10, g);
            DigitDisplay[5].Draw(sec % 10, g);
            //MicroSecDisplay.Draw(ms / 100, g);
            if (am_pm == ' ')
                AmPmDisplay.Draw(g);
            else
                AmPmDisplay.Draw(am_pm, g);
        }

        // Timer used to refresh clock display
        private void OnClockTimer(object sender, System.EventArgs e)
        {
            //DisplayTime(graphics);
        }

        public event EventHandler TimerEventHandler;

        // Keeping the colon timer, gives a special effect of colon blinking
        // independent of the seconds or 1/10 seconds display
        private void OnColonTimer(object sender, System.EventArgs e)
        {
            //display the 2 colons between the hours-minutes and mi
            
            ColonDisplay[0].DrawColon(graphics, ColonType.Rectangular, blink);
            ColonDisplay[1].DrawColon(graphics, ColonType.Rectangular, blink);
            if (clockType == ClockType.Freeze)
                blink = false;
            else
                blink = !blink;

            this.Invalidate();
            if (TimerEventHandler != null)
            {
                TimerEventHandler(null, null);
            }
        }

        // function to prepare the digital clock panels by dividing the rectangle
        // It is assumed that the height of each digit is double that of it's width
        // Spacing betweent the digits is 10% of the width
        // The colon characters occupy 50% of width of the digits
        private void PreparePanels()
        {
            // from the above assumptions for height and width
            // the height should be 2.4 units and width 8.8 units :-)
            // check height and width whichever is dominant and adjust the other
            // and set up margins
            Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);

            // widths, spacings and margins
            // height of colon display is same as a digit
            int DigitWidth, DigitHeight, ColonWidth, Spacing;
            float HMargin = 0, // left and right margin
                    VMargin = 0; // top and bottom margin

            // Calculate a digit width (which is our unit) from the above metrics
            // and settle for the least value
            int WidthUnit = (int)(rect.Width / 8.8F);
            int HeightUnit = (int)(rect.Height / 2.4F);
            DigitWidth = (WidthUnit < HeightUnit) ? WidthUnit : HeightUnit;

            DigitHeight = 2 * DigitWidth;  // height is twice of width
            ColonWidth = DigitWidth / 2;  // colon width is half of a digit
            Spacing = DigitWidth / 10;
            if (Spacing < 1) Spacing = 1; // atleast a spacing of 1 is required
            HMargin = (rect.Width - (8.8F * DigitWidth)) / 2;
            VMargin = (rect.Height - DigitHeight) / 2;

            // This is the basic rectangle, offset it as required
            Rectangle basicRect = new Rectangle(0, 0, (int)DigitWidth, (int)DigitHeight);
            int XOffset, YOffset;
            Rectangle calcRect;  // calculated rectangle for a panel
            // Y offset is same for all elements, expcept 1/10 second and AM/PM display
            YOffset = (int)(VMargin);

            // create digit panels.  6 digits
            if (DigitDisplay == null)
                DigitDisplay = new DigitalDisplay[6];
            for (int i = 0; i < 6; i++)
            {
                calcRect = basicRect;
                XOffset = (int)(HMargin + (Spacing * (i + 2 + (i / 2))) + (i * DigitWidth) + ((i / 2) * ColonWidth));
                calcRect.Offset(XOffset, YOffset);
                if (DigitDisplay[i] == null)
                    DigitDisplay[i] = new DigitalDisplay(calcRect);
                else
                    DigitDisplay[i].CalculateAllParameters(calcRect);
            }

            if (ColonDisplay == null)
                ColonDisplay = new DigitalDisplay[2];
            // for first colon
            calcRect = basicRect;
            calcRect.Width = (int)ColonWidth;
            XOffset = (int)(HMargin + 3 * Spacing + 2 * DigitWidth);
            calcRect.Offset(XOffset, YOffset);
            if (ColonDisplay[0] == null)
                ColonDisplay[0] = new DigitalDisplay(calcRect);
            else
                ColonDisplay[0].CalculateAllParameters(calcRect);

            // for second colon
            calcRect = basicRect;
            calcRect.Width = (int)ColonWidth;
            XOffset = (int)((6 * Spacing) + (4 * DigitWidth) + ColonWidth + HMargin);
            calcRect.Offset(XOffset, YOffset);
            if (ColonDisplay[1] == null)
                ColonDisplay[1] = new DigitalDisplay(calcRect);
            else
                ColonDisplay[1].CalculateAllParameters(calcRect);

            // for displaying 'A'(AM) or 'P' (PM)
            calcRect = basicRect;
            calcRect.Width = (int)ColonWidth;
            calcRect.Height = calcRect.Height / 2;
            XOffset = (int)((10 * Spacing) + (6 * DigitWidth) + (2 * ColonWidth) + HMargin);
            calcRect.Offset(XOffset, (int)(YOffset + DigitHeight / 2.0 + 1));
            if (AmPmDisplay == null)
                AmPmDisplay = new DigitalDisplay(calcRect);
            else
                AmPmDisplay.CalculateAllParameters(calcRect);

            // for displaying 1/10 of a second
            // reuse AM/PM display panel rectangle
            // only change Y coordinate, shift upwards
            calcRect.Y = YOffset - 1; // just to keep it apart from AM/PM display
            if (MicroSecDisplay == null)
                MicroSecDisplay = new DigitalDisplay(calcRect);
            else
                MicroSecDisplay.CalculateAllParameters(calcRect);
        }

        // On resize of control recalculate the rectangles for display
        // Also recreate the graphics so that the clipping region is updated
        private void OnResize(object sender, System.EventArgs e)
        {
            lock (this)
            {
                PreparePanels();
                graphics.Dispose();
                graphics = Graphics.FromImage(bitmap);
                graphics.Clear(BackColor);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -