GDI+画图问题,请高手指点
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Point P1 = new Point();
Point P2 = new Point();
bool isMouseDown = false;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect1=new Rectangle(50, 50, 200, 100);
Draw(g, rect1);
}
private void Draw(Graphics g, Rectangle rect)
{
GraphicsPath roundedRect = new GraphicsPath();
roundedRect.AddArc(rect.X, rect.Y, rect.Width, rect.Height, 0, 360);
roundedRect.CloseFigure();
Region pathRegion = new Region(roundedRect);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (isMouseDown == false)
{
isMouseDown = true;
P1.X = e.X;
P1.Y = e.Y;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{
P2.X = e.X;
P2.Y = e.Y;
this.Invalidate();
}
}
}
}
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Point P1 = new Point();
Point P2 = new Point();
bool isMouseDown = false;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawEllipse(new Pen(Color.Red, 3), 1, 1, 5, 5);
g.DrawRectangle (new Pen(Color .Blue ,3),P1.X>P2.X?P2.X:P1.X ,P1.Y>P2.Y?P2.Y:P1.Y,Math.Abs (P2.X-P1.X),Math .Abs (P2.Y-P1.Y));
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (isMouseDown == false)
{
isMouseDown = true;
P1.X = e.X;
P1.Y = e.Y;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{
P2.X = e.X;
P2.Y = e.Y;
this.Invalidate();
}
}
}
}