• 大小: 0.09M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-29
  • 语言: C#
  • 标签: 时钟  

资源简介

通过代码绘制正在运行的时钟图像,封装成了用户控件,值得参考学习

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test
{
    public partial class AnalogClock : UserControl
    {
        const float PI = 3.141592654F;

        DateTime dateTime;

        float fRadius;
        float fCenterX;
        float fCenterY;
        float fCenterCircleRadius;

        float fHourLength;
        float fMinLength;
        float fSecLength;

        float fHourThickness;
        float fMinThickness;
        float fSecThickness;

        bool bDraw5MinuteTicks = true;
        bool bDraw1MinuteTicks = true;
        float fTicksThickness = 1;

        Color hrColor = Color.DarkMagenta;
        Color minColor = Color.Green;
        Color secColor = Color.Red;
        Color circleColor = Color.Red;
        Color ticksColor = Color.Black;

        //private System.Windows.Forms.Timer timer1;
        //private System.ComponentModel.IContainer components;

        bool bActive = true;
        DateTime relativeDateTime = new DateTime();//相对时间
        TimeSpan spDiffTime = new TimeSpan();
        double dDiffSeconds = 0;


        //public event EventHandler TimeChanged;

        public AnalogClock()
        {
            InitializeComponent();
        }

        private void AnalogClock_Load(object sender System.EventArgs e)
        {
            dateTime = DateTime.Now;
            this.AnalogClock_Resize(sender e);
        }

        private void timer1_Tick(object sender System.EventArgs e)
        {
            //if (dDiffSeconds == 0)
            //{
            //    this.dateTime = DateTime.Now;
            //}
            //else
            //{
            //    this.dateTime = System.DateTime.Now - spDiffTime;
            //}
            this.dateTime = RelativeDateTime;
            this.Refresh();
            //TimeChanged(null null);
        }

        public void Start()
        {
            timer1.Enabled = true;
            this.Refresh();
        }

        public void Stop()
        {
            timer1.Enabled = false;
        }

        private void DrawLine(float fThickness float fLength Color color float fRadians System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.DrawLine(new Pen(color fThickness)
                fCenterX - (float)(fLength / 9 * System.Math.Sin(fRadians))
                fCenterY + (float)(fLength / 9 * System.Math.Cos(fRadians))
                fCenterX + (float)(fLength * System.Math.Sin(fRadians))
                fCenterY - (float)(fLength * System.Math.Cos(fRadians)));
        }

        private void DrawPolygon(float fThickness float fLength Color color float fRadians System.Windows.Forms.PaintEventArgs e)
        {

            PointF A = new PointF((float)(fCenterX + fThickness * 2 * System.Math.Sin(fRadians 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9378  2016-01-22 17:34  TestUseControl\Test\AnalogClock.cs

     文件       9378  2016-01-22 17:34  TestUseControl\Test\AnalogClock.cs.bak

     文件       1965  2016-01-22 17:34  TestUseControl\Test\AnalogClock.Designer.cs

     文件       1965  2016-01-22 17:34  TestUseControl\Test\AnalogClock.Designer.cs.bak

     文件       6008  2016-01-22 17:34  TestUseControl\Test\AnalogClock.resx

     文件      14336  2020-09-03 14:39  TestUseControl\Test\bin\Debug\Test.exe

     文件      32256  2016-01-22 17:34  TestUseControl\Test\bin\Debug\Test.pdb

     文件      14328  2020-09-03 14:39  TestUseControl\Test\bin\Debug\Test.vshost.exe

     文件        490  2009-06-11 05:14  TestUseControl\Test\bin\Debug\Test.vshost.exe.manifest

    ..A.SH.         9  2019-09-24 09:34  TestUseControl\Test\bin\Debug\_desktop.ini

    ..A.SH.         9  2019-09-24 09:34  TestUseControl\Test\bin\_desktop.ini

     文件        739  2016-01-22 17:26  TestUseControl\Test\Form1.cs

     文件        739  2016-01-22 17:26  TestUseControl\Test\Form1.cs.bak

     文件       3789  2016-01-22 17:26  TestUseControl\Test\Form1.Designer.cs

     文件       3789  2016-01-22 17:26  TestUseControl\Test\Form1.Designer.cs.bak

     文件       5814  2016-01-22 17:26  TestUseControl\Test\Form1.resx

    ..A.SH.         9  2019-09-24 09:34  TestUseControl\Test\obj\Debug\TempPE\_desktop.ini

     文件        180  2016-01-22 17:34  TestUseControl\Test\obj\Debug\Test.AnalogClock.resources

     文件        402  2016-01-22 17:50  TestUseControl\Test\obj\Debug\Test.csproj.FileListAbsolute.txt

     文件        911  2016-01-22 17:34  TestUseControl\Test\obj\Debug\Test.csproj.GenerateResource.Cache

     文件      41447  2018-01-25 13:51  TestUseControl\Test\obj\Debug\Test.exe

     文件        180  2016-01-22 17:34  TestUseControl\Test\obj\Debug\Test.Form1.resources

     文件      32256  2016-01-22 17:34  TestUseControl\Test\obj\Debug\Test.pdb

     文件        180  2016-01-22 17:34  TestUseControl\Test\obj\Debug\Test.Properties.Resources.resources

    ..A.SH.         9  2019-09-24 09:34  TestUseControl\Test\obj\Debug\_desktop.ini

    ..A.SH.         9  2019-09-24 09:34  TestUseControl\Test\obj\_desktop.ini

     文件        485  2016-01-22 17:13  TestUseControl\Test\Program.cs

     文件        485  2016-01-22 17:13  TestUseControl\Test\Program.cs.bak

     文件       1340  2016-01-22 17:00  TestUseControl\Test\Properties\AssemblyInfo.cs

     文件       1340  2016-01-22 17:00  TestUseControl\Test\Properties\AssemblyInfo.cs.bak

............此处省略23个文件信息

评论

共有 条评论