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