首页

画图时钟示例(Graphics入门级示例)

c#

2020-8-31

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

namespace shizhong
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int j,m,h,r; string a,b,c;
            Graphics g = this.CreateGraphics();
            Pen pen1 = new Pen(Color.Red, 3);
            Pen pen2 = new Pen(Color.BurlyWood , 2);
            double x, y, i,x0,y0,x1,y1;
            float p,q;
           
           g.Clear(this.BackColor);
           r = textBox1.Text.Length;
          
               j = Convert.ToInt16(textBox1.Text.Substring (r-2));
               m = Convert.ToInt16(textBox1.Text.Substring(r- 5,2));
               h = Convert.ToInt16(textBox1.Text.Substring(r - 8,2));
            p = 150;
            q = 100;
            i = 0;
            while (i < 12)
            {    x1 = Math.Sin(2 * i * Math.PI / 12) * 55;
                y1 = Math.Cos(2 * i * Math.PI / 12) * 55;
                x0 = x1/55* 50;
                y0 = y1/55* 50;
                g.DrawLine(pen2, p   (float)x0, q   (float)y0, p   (float)x1, q   (float)y1);
                g.DrawEllipse(pen2, p - 60, q - 60, 120, 120);
                i = i   1;

            }
            i = j;
            x = Math.Sin(2 * i * Math.PI / 60) * 50;
            y = -Math.Cos(2 * i * Math.PI / 60) * 50;
            g.DrawLine(pen1, p   0, q   0, p   (float)x, q  (float)y);
            j  = 1;
         if (j == 60)
            {
                j = 0; m = m   1; 
             if (m == 60) { m = 0; h  = 1;

             if (h == 24) h = 0;
             }
            
          }
           
        if (j < 10) c = "0"; else c = "";      
        if (m < 10) b = "0"; else b = ""; 
         if (h < 10) a = "0"; else a = "";
            textBox1.Text = a Convert.ToString(h) ":" b Convert.ToString(m) ":" c  Convert.ToString(j);
                
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen1 = new Pen(Color.Red, 3);
            double x1, y1, i,x0,y0;
            float p,q;  
            p = 150;
            q = 100;
            i = 0;
           
         //  x1 = Math.Sin(2*i*Math.PI /60)*55;
         //  y1= Math.Cos(2*i * Math.PI / 60)*55;
         //   x0 = x1; y0 = y1;
          
          
            while (i < 12)
            {  

            x1 = Math.Sin(2 * i * Math.PI / 12) * 55;
            y1 = Math.Cos(2 * i * Math.PI / 12) * 55;
            x0 = Math.Sin(2 * i * Math.PI / 12) * 50;
            y0 = Math.Cos(2 * i * Math.PI / 12) * 50;
            g.DrawLine(pen1, p   (float)x0, q  (float)y0, p   (float)x1, q  (float)y1);
            g.DrawEllipse(pen1, p-60, q-60, 120, 120);
                i = i   1;
                Application.Exit();
           
            }
           
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
      
    }
}

资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
shizhong/shizhong/bin/Debug/shizhong.exe , 10752
shizhong/shizhong/bin/Debug/shizhong.pdb , 30208
shizhong/shizhong/bin/Debug/shizhong.vshost.exe , 14328
shizhong/shizhong/bin/Debug/shizhong.vshost.exe.manifest , 490
shizhong/shizhong/Form1.cs , 3369
shizhong/shizhong/Form1.Designer.cs , 3642
shizhong/shizhong/Form1.resx , 6008
shizhong/shizhong/obj/Debug/shizhong.csproj.FileListAbsolute.txt , 1094
shizhong/shizhong/obj/Debug/shizhong.csproj.GenerateResource.Cache , 847
shizhong/shizhong/obj/Debug/shizhong.exe , 10752
shizhong/shizhong/obj/Debug/shizhong.Form1.resources , 180
shizhong/shizhong/obj/Debug/shizhong.pdb , 30208
shizhong/shizhong/obj/Debug/shizhong.Properties.Resources.resources , 180
shizhong/shizhong/Program.cs , 489
shizhong/shizhong/Properties/AssemblyInfo.cs , 1372
shizhong/shizhong/Properties/Resources.Designer.cs , 2866
shizhong/shizhong/Properties/Resources.resx , 5612
shizhong/shizhong/Properties/Settings.Designer.cs , 1093
shizhong/shizhong/Properties/Settings.settings , 249
shizhong/shizhong/shizhong.csproj , 3727
shizhong/shizhong.sln , 914
shizhong/shizhong.suo , 15360
shizhong/角度图.cs , 3301
shizhong/角度图.Designer.cs , 3574
shizhong/角度图.resx , 6008
没有账号? 忘记密码?

社交账号快速登录