zoukankan      html  css  js  c++  java
  • 标准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);
               
            }
        }
    }
    自动驱动未来
  • 相关阅读:
    分形与数据结构第一篇(神奇的色子)
    画图小工具第二篇
    画图小工具第一篇
    图形界面第一篇
    回合制对战游戏第二篇
    回合对战制游戏第一篇(初识java)
    技术+态度+人品
    排序的一些方法(稳定性,内外排序,时间空间复杂度)
    暂时性死区
    vue传值(父子传值,非父子传值)
  • 原文地址:https://www.cnblogs.com/rb-huang/p/hrb_190417_1.html
Copyright © 2011-2022 走看看