C#利用鼠標繪圖


        bool G_MouseFlag;
        Pen pen = new Pen(Color.Black);
        Point lastPoint;
        private void _018_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics graphics = this.CreateGraphics();
            if (lastPoint.Equals(Point.Empty))//判斷繪圖開始點是否為空
            {
                lastPoint = new Point(e.X, e.Y);//記錄鼠標當前位置
            }
            if (G_MouseFlag)//開始繪圖
            {
                Point currentPoint = new Point(e.X, e.Y);//獲取鼠標當前位置
                graphics.DrawLine(pen, currentPoint, lastPoint);//繪圖
            }
            lastPoint = new Point(e.X,e.Y);//記錄鼠標當前位置
        }

        private void _018_MouseDown(object sender, MouseEventArgs e)
        {
            G_MouseFlag = true;//開始繪圖標識設置為true
        }

        private void _018_MouseUp(object sender, MouseEventArgs e)
        {
            G_MouseFlag = false;//開始繪圖標識設置為false
        }
        //畫圓
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics graphics = this.CreateGraphics();
            Rectangle gle=new Rectangle(20,20,200,200);
            graphics.DrawEllipse(pen,gle);
        }

 


免責聲明!

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



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