C# WinForm制作黑酷唯美时空钟表

C# WinForm制作黑酷唯美时空钟表声明变量:引发事件:添加图片控件:添加时间:

欢迎大家来到IT世界,在知识的湖畔探索吧!

#头条创作挑战赛##中国和新加坡将举行海上联合演习##头条家时光#

C# WinForm制作黑酷唯美时空钟表

声明变量:

        private Graphics g;        private Pen pen;        private FontFamily MyFamily;        private Font MyFont;        private int w;        private int h;

欢迎大家来到IT世界,在知识的湖畔探索吧!

引发事件:

欢迎大家来到IT世界,在知识的湖畔探索吧!protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias; //

            g.SmoothingMode = SmoothingMode.HighQuality;//绘图模式默认为粗糙模式,将会出现锯齿!



            w = pictureBox1.Width;

            h = pictureBox1.Height;

            int x1 = pictureBox1.Location.X;

            int y1 = pictureBox1.Location.Y;

         


          

            g.FillEllipse(Brushes.Black, x1 + 2, y1 + 2, w - 4, h - 4); //外圆

            MyFamily = new System.Drawing.FontFamily("Impact"); //字体

            MyFont = new System.Drawing.Font(MyFamily, 20, FontStyle.Bold, GraphicsUnit.Pixel);

            g.DrawString("中华时钟", MyFont, Brushes.Yellow, x1 + w - 130, y1 + h - 260);
            g.DrawString("唯美时图", MyFont, Brushes.Pink, x1 + w - 830, y1 + h - 260);

            MyFamily = new System.Drawing.FontFamily("Times New Roman");

            MyFont = new System.Drawing.Font(MyFamily, 39, FontStyle.Bold, GraphicsUnit.Pixel);//字体大小

            pen = new Pen(Color.White, 2);

            g.DrawEllipse(pen, x1 + 7, y1 + 7, w - 13, h - 13);// 内圆

            g.TranslateTransform(x1 + (w / 2), y1 + (h / 2));//重新设置坐标原点

            g.FillEllipse(Brushes.Red, -5, -5, 10, 10);//绘制表盘中心

            //g.TranslateTransform(w/2,h/2);

            for (int x = 0; x < 60; x++) //小刻度

            {

                g.FillRectangle(Brushes.White, new Rectangle(-2, (System.Convert.ToInt16(h - 8) / 2 - 2) * (-1), 3, 10));

                g.RotateTransform(6);//偏移角度

            }

            for (int i = 12; i > 0; i--) //大刻度

            {

                string myString = i.ToString();

                //绘制整点刻度

                g.FillRectangle(Brushes.White, new Rectangle(-3, (System.Convert.ToInt16(h - 8) / 2 - 2) * (-1), 6, 20));

                //绘制数值

                g.DrawString(myString, MyFont, Brushes.Red, new PointF(myString.Length * (-6), (h - 8) / -2 + 26));

                //顺时针旋转度

                g.RotateTransform(-30);//偏移角度

            }
        }

添加图片控件:

 private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            g = e.Graphics;

            //绘图模式默认为粗糙模式,将会出现锯齿!

            g.SmoothingMode = SmoothingMode.AntiAlias;

            g.SmoothingMode = SmoothingMode.HighQuality;

            g.TranslateTransform(w / 2, h / 2);//重新设置坐标原点

            //获得系统时间值

            int second = DateTime.Now.Second;
            int minute = DateTime.Now.Minute;
            int hour = DateTime.Now.Hour;
            //每分偏移读,分针偏移 = 当前分 * 6 + 当前秒 *(/ 60)

            //每小时偏移读,时针偏移 = 当前时 * 30 + 当前分 *(/ 60)+当前秒 *(/ 60 / 60)

          

            //绘秒针

            pen = new Pen(Color.Red, 1);

            pen.EndCap = LineCap.ArrowAnchor;

            g.RotateTransform(6 * second);

            float y = (float)((-1) * (h / 2.75));

            g.DrawLine(pen, new PointF(0, 0), new PointF((float)0, y));

            ////绘分针

            pen = new Pen(Color.Yellow, 4);

            

            g.RotateTransform(-6 * second); //恢复系统偏移量,再计算下次偏移

            g.RotateTransform((float)(second * 0.1 + minute * 6));

            y = (float)((-1) * ((h - 20) / 2.75));

            g.DrawLine(pen, new PointF(0, 0), new PointF((float)0, y));

            ////绘时针

            pen = new Pen(Color.White, 8);

           

            g.RotateTransform((float)(-second * 0.1 - minute * 6));//恢复系统偏移量,再计算下次偏移

            g.RotateTransform((float)(second * 0.01 + minute * 0.1 + hour * 30));

            y = (float)((-1) * ((h - 55) / 2.75));

            g.DrawLine(pen, new PointF(0, 0), new PointF((float)0, y));
        }

添加时间:

欢迎大家来到IT世界,在知识的湖畔探索吧!private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Invalidate();
        }

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/38196.html

(0)

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们YX

mu99908888

在线咨询: 微信交谈

邮件:itzsgw@126.com

工作时间:时刻准备着!

关注微信