110,568
社区成员
发帖
与我相关
我的任务
分享
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
DrawSquare(e.Graphics);
}
private void DrawSquare(Graphics g)
{
string[] split = "10,10,90,90".Split(',');
p_start.X = int.Parse(split[0]);
p_start.Y = int.Parse(split[1]);
p_end.X = int.Parse(split[2]);
p_end.Y = int.Parse(split[3]);
try
{
//绘制矩形
if (p_end.X < p_start.X)
{
int a = p_end.X;
p_end.X = p_start.X;
p_start.X = a;
}
if (p_end.Y < p_start.Y)
{
int a = p_end.Y;
p_end.Y = p_start.Y;
p_start.Y = a;
}
//g = pictureBox1.CreateGraphics();
//g.DrawImage(pictureBox1.Image, 0, 0);
Pen pen = new Pen(Color.Red, 2);
g.DrawRectangle(pen, p_start.X, p_start.Y, p_end.X - p_start.X, p_end.Y - p_start.Y);
}
catch
{
throw;
}
}