其他分享
首页 > 其他分享> > 标准十字座标系

标准十字座标系

作者:互联网

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 CoordinateSystem
{
    public partial class Form1 : Form
    {
        int orgX = 20;
        int orgY = 20;//原点距离边框左,下距离
        int move = 20;//格子间隔
        int timerI = 0;
       
        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 1000;
            timer1.Enabled = true;
        }
       
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
           
                       Draw draw = new Draw();
            draw.DrawX(move,panel1,orgX,orgY);
            draw.DrawY(move, panel1, orgX, orgY);
           
        }         private void timer1_Tick(object sender, EventArgs e)
        {
            Graphics g = panel1.CreateGraphics();
          
            //double a = Math.Sin(timerI);
            //double c = a * 100;
            //int b = (int)c;
            //g.DrawLine(new Pen(Color.Red), new Point(orgX, panel1.Height - orgY),
            //           new Point(orgX + timerI, panel1.Width - orgY - b));
            g.DrawLine(new Pen(Color.Red), new Point(orgX+timerI*10, panel1.Height - orgY- timerI * 10),
                                       new Point(orgX + timerI * 10+10, panel1.Height - orgY- timerI * 10-10));
            timerI += 1;         }
    }
    public class Draw
    {
        //X轴方法
        public void DrawX(int move,Panel panel,int orgX,int orgY)//画X轴上分格
        {
           
          
            int a = (panel.Width/2) / move;//X轴有多少格
            Graphics g = panel.CreateGraphics();
           
            g.DrawLine(new Pen(Color.Black, 3), new Point(panel.Width/2, panel.Height),//画X轴长线
                                                new Point(panel.Width/2, 0));
            for (int i = 0; i < a; i++)             {
                g.DrawLine(new Pen(Color.Black, 3), new Point(panel.Width/2+ move * i, panel.Height/2),
                           new Point(panel.Width / 2 + move * i, panel.Height / 2 - 4));//划分+格子
                g.DrawLine(new Pen(Color.Black, 3),new Point(panel.Width / 2 - move * i, panel.Height / 2),
                            new Point(panel.Width / 2 - move * i, panel.Height / 2 - 4));//划分-格子
                g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, panel.Width / 2 + move * i,
                                                                      panel.Height / 2 + 4 );//写X轴+的数字                 if (i!=0)
                {
                    g.DrawString("-" + i.ToString(), new Font("宋体", 8f), Brushes.Black, panel.Width / 2 - move * i,
                                                                                          panel.Height / 2 + 4);//写X轴-的数字
                }
               
            }
            g.DrawString("X轴", new Font("宋体", 10f), Brushes.Black, panel.Width-30, panel.Height/2+20);         }         public void DrawY(int move,Panel pan,int orgX,int orgY)
        {
            Graphics g = pan.CreateGraphics();
            g.DrawLine(new Pen(Color.Black, 3), new Point(0, pan.Height/2),
                                                new Point(pan.Width, pan.Height / 2));//画Y轴长线             int a = (pan.Height/2) / move;
            for (int i = 0; i < a; i++)
            {
                g.DrawLine(new Pen(Color.Black, 3), new Point(pan.Width/2, pan.Height/2 - move * i),
                           new Point(pan.Width / 2 + 4, pan.Height / 2 - move * i));
                g.DrawLine(new Pen(Color.Black, 3), new Point(pan.Width / 2, pan.Height / 2 + move * i),
                           new Point(pan.Width / 2 + 4, pan.Height / 2 + move * i));
                if (i!=0)
                {
                    g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, pan.Width / 2 - 10,
                    pan.Height / 2 - move * i);
                    g.DrawString("-"+i.ToString(), new Font("宋体", 8f), Brushes.Black, pan.Width / 2 - 15,
                    pan.Height / 2 + move * i);
                }
               
            }
            g.DrawString("Y轴", new Font("宋体", 10f),Brushes.Black, orgX, orgY - 20);
           
        }
    }
}

标签:Width,move,Height,座标,标准,十字,new,pan,panel
来源: https://www.cnblogs.com/rb-huang/p/hrb_190417_2.html