I have found this code online, and I want to use it to draw a little blue box, on top of my drawing. But When I click on the picturebox the blue box appears, but it redraws my entire picture box, this is a problem because I have a very complex picture, ans it takes a few seconds to redraw. Is there any way around the Invalidate? Perhaps a picturebox inside a picturebox, with the backpicturebox my complex drawing, and the frontpicturebox the blue box with a refresh? I cant seem to get the front picturebox backgroundcolor to transparent, could anybody help me?
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determine the initial rectangle coordinates...
if (MeasureMentimported && !selectieBezig)
{
RectStartPoint = e.Location;
//Invalidate();
selectieBezig = true;
}
}
// Draw Rectangle
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
//Als er niet links wordt geklikt, dan gewoon weer terug.
if (e.Button != MouseButtons.Left)
return;
//Alleen als de measurementfile is geladen, gaan we kijken of er iets te selecteren valt.
if (MeasureMentimported && selectieBezig)
{
Point tempEndPoint = e.Location;
int X1 = Math.Min(RectStartPoint.X, tempEndPoint.X);
int Y1 = Math.Min(RectStartPoint.Y, tempEndPoint.Y);
int X2 = Math.Max(RectStartPoint.X, tempEndPoint.X);
int Y2 = Math.Max(RectStartPoint.Y, tempEndPoint.Y);
Rect.Location = new Point(X1, Y1);
Rect.Size = new Size(X2 - X1, Y2 - Y1);
picTekenvlak.Invalidate();
//Rect.Location = new Point(
// Math.Min(RectStartPoint.X, tempEndPoint.X),
// Math.Min(0, 1000));
//Rect.Size = new Size(
// Math.Abs(RectStartPoint.X - tempEndPoint.X),
// Math.Abs(1000));
// MessageBox.Show("k");
}
}
// Draw Area
//
private void pictureBox1_Paint1(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (MeasureMentimported)
{
if (Rect != null && Rect.Width > 0 && Rect.Height > 0)
{
e.Graphics.FillRectangle(selectionBrush, Rect);
}
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
selectieBezig = false;
if (e.Button == MouseButtons.Right)
{
if (Rect.Contains(e.Location))
{
Console.WriteLine("Right click");
}
}
}