• 标准panel内坐标系(没有负方向)


    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);
               
            }
          
        }
        public class Draw
        {
            //X轴方法
            public void DrawX(int move,Panel panel,int orgX,int orgY)//画X轴上分格
            {
               
              
                int a = (panel.Width - 2*orgX) / move;//X轴有多少格
                Graphics g = panel.CreateGraphics();
               
                g.DrawLine(new Pen(Color.Black, 3), new Point(orgX, panel.Height - orgY),//画X轴长线
                                                    new Point(panel.Width - orgX, panel.Height - orgY));

                for (int i = 0; i < a; i++)
                {
                    g.DrawLine(new Pen(Color.Black, 3), new Point(orgX + move * i, panel.Height - orgY),
                                                        new Point(orgX + move * i, panel.Height -orgY-4));//划分间隔格子
                    g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, orgX + move * i,
                                                                          panel.Height - orgY+4 );//写X轴间隔的数字
                }
                g.DrawString("X轴", new Font("宋体", 10f), Brushes.Black, panel.Width - 25, panel.Height - orgY-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(orgX, pan.Height-orgY),
                                                    new Point(orgX, 20));//画Y轴长线
                int a = (pan.Height - 2 * orgY) / move;
                for (int i = 0; i < a; i++)
                {
                    g.DrawLine(new Pen(Color.Black, 3), new Point(orgX, pan.Height - orgY - move * i),
                               new Point(orgX + 4, pan.Height - orgY - move * i));
                    g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, orgX - 10,
                        pan.Height - orgY - move * i);
                }
                g.DrawString("Y轴", new Font("宋体", 10f),Brushes.Black, orgX, orgY - 20);
               
            }
        }
    }
    自动驱动未来
  • 相关阅读:
    启动tomcat时jmx port被占用
    Intellij Idea下tomcat设置自动编译
    IDEA的快捷键的使用
    IDEA2017注册码
    hosts文件路径及文件介绍
    关于JAVA开发工具IDEA使用
    如何用Word编辑参考文献------这是引用一位大师的
    TDK标签在SEO中的应用
    简单的线条不简单的画
    HTML--网页自动跳转 5种方法
  • 原文地址:https://www.cnblogs.com/rb-huang/p/hrb_190417_1.html
Copyright © 2020-2023  润新知