public Form1()
{
InitializeComponent();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
}
private bool isMouseDown;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (!isMouseDown)
return;
Graphics gr = Graphics.FromImage(pictureBox1.Image);
gr.DrawRectangle(new Pen(Color.Red), e.X-5, e.Y-5, 10, 10);
gr.Dispose();
pictureBox1.Invalidate();
}