C#:画图坐标平移,重绘,及不消失的方法。

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 RactangleDrawAndMatrix
{
    public partial class Form1 : Form
    {
        float move = 50f;
        public Form1()
        {
            InitializeComponent();
          
        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {//这里画图是随着控件的刷新而刷新的,就是说只要控件不消失图就不消失。下面的则可能消失
            Graphics g = panel1.CreateGraphics();
            g.DrawRectangle(new Pen(Color.Black, 5), new Rectangle(50, 50, panel1.Width - 100, panel1.Height - 100));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Refresh();
            Graphics g = panel1.CreateGraphics();
            Pen blackPen = new Pen(Color.Black, 2);
            Point point1 = new Point(1, 1);
            Point point2 = new Point(100, 100);
            g.DrawRectangle(blackPen, 1, 1, 100, 200);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Refresh();//刷新,清除所有图形
            Graphics g = panel1.CreateGraphics();
            g.TranslateTransform(panel1.Width / 2, panel1.Height / 2);
            g.RotateTransform(90);//旋转90度
           // Pen blackPen = new Pen(Color.Black, 2);
            //Point point1 = new Point(1, 1);
           // Point point2 = new Point(100, 100);
           
          
            g.DrawRectangle(new Pen(Color.Blue, 2), new Rectangle(0, 0, 100, 200));
        }
       
    }
}
自动驱动未来
原文地址:https://www.cnblogs.com/rb-huang/p/hrb.html