1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (checkBox1.Checked)
{
e.Graphics.DrawEllipse(new Pen(Color.Black, 1f), rect);
}
else
{
e.Graphics.DrawRectangle(new Pen(Color.Black, 1f), rect);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
startPoint = new Point(e.X, e.Y);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
size = new Size(e.X - startPoint.X, e.Y - startPoint.Y);
pictureBox1.Invalidate();
rect = new Rectangle(startPoint, size);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
Graphics graph;
graph = Graphics.FromImage(pictureBox1.Image);
graph.DrawRectangle(new Pen(Color.Black, 1f), rect);
mouseDown = false;
} |
Partager