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));
        }
       
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM