0
I’m moving one picturebox over another with a mouse. But she keeps leaving a trail behind when I move the mouse, the trail disappears right away, but there’s a way to remove it?
I tried to take the refresh()
When the image moves, it takes off the trace but it hangs too much, moves too slow, is giving locks.
Here the code:
private void picImage_MouseMove(object sender, MouseEventArgs e)
{
if (picImage.Image == null)
return;
if(act)
UpdateZoomedImage(e);
picZoom.Location = new Point(e.X+40, e.Y+40);
picZoom.Refresh();
}
zoom code:
private void UpdateZoomedImage(MouseEventArgs e)
{
// Calculate the width and height of the portion of the image we want
// to show in the picZoom picturebox. This value changes when the zoom
// factor is changed.
int zoomWidth = picZoom.Width / _ZoomFactor;
int zoomHeight = picZoom.Height / _ZoomFactor;
// Calculate the horizontal and vertical midpoints for the crosshair
// cursor and correct centering of the new image
int halfWidth = zoomWidth / 2;
int halfHeight = zoomHeight / 2;
// Create a new temporary bitmap to fit inside the picZoom picturebox
Bitmap tempBitmap = new Bitmap(zoomWidth, zoomHeight, PixelFormat.Format24bppRgb);
// Create a temporary Graphics object to work on the bitmap
Graphics bmGraphics = Graphics.FromImage(tempBitmap);
// Clear the bitmap with the selected backcolor
bmGraphics.Clear(_BackColor);
// Set the interpolation mode
bmGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the portion of the main image onto the bitmap
// The target rectangle is already known now.
// Here the mouse position of the cursor on the main image is used to
// cut out a portion of the main image.
bmGraphics.DrawImage(picImage.Image,
new Rectangle(0, 0, zoomWidth, zoomHeight),
new Rectangle(e.X - halfWidth, e.Y - halfHeight, zoomWidth, zoomHeight),
GraphicsUnit.Pixel);
// Draw the bitmap on the picZoom picturebox
picZoom.Image = tempBitmap;
// Draw a crosshair on the bitmap to simulate the cursor position
bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight - 4, halfWidth + 1, halfHeight - 1);
bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight + 6, halfWidth + 1, halfHeight + 3);
bmGraphics.DrawLine(Pens.Black, halfWidth - 4, halfHeight + 1, halfWidth - 1, halfHeight + 1);
bmGraphics.DrawLine(Pens.Black, halfWidth + 6, halfHeight + 1, halfWidth + 3, halfHeight + 1);
// Dispose of the Graphics object
bmGraphics.Dispose();
// Refresh the picZoom picturebox to reflect the changes
picZoom.Refresh();
}
what your Updatezoomedimage code is ?
– Rovann Linhalis
I edited the post with the code.
– Brugo
I believe the problem is, that at each mouse moved point, you redesign the image completely, I don’t know if it works, but try to call the method
this.SuspendLayout();
of the form, before drawing, and after it is ready, thethis.ResumeLayout();
. If it doesn’t work, put a timer to delay the drawing process, only running it once, at the end of the movement.– Rovann Linhalis
Thanks buddy, with timer worked perfectly.
– Brugo
what beauty! I put as an answer, if you want to mark and close the question =]
– Rovann Linhalis