volevo solo mettere una selezione sul mio picturebox.image ma questo è appena diventato peggiore di una situazione poco fastidiosa. Ho pensato a un'altra casella di immagine sopra la finestra principale ma a me sembrava così laboriosa. Ho bisogno di sapere se c'è un modo per creare un'area di selezione (che sarà un'area blu trasparente a metà) su una picturebox.image che verrà disegnata con il mouse e non dovrebbe modificare l'immagine su cui sta lavorando.Come selezionare un'area su PictureBox.Image con il mouse in C#
campione:
// Start Rectangle
//
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determine the initial rectangle coordinates...
RectStartPoint = e.Location;
Invalidate();
}
// Draw Rectangle
//
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Point tempEndPoint = e.Location;
Rect =
new Rectangle(
Math.Min(RectStartPoint.X, tempEndPoint.X),
Math.Min(RectStartPoint.Y, tempEndPoint.Y),
Math.Abs(RectStartPoint.X - tempEndPoint.X),
Math.Abs(RectStartPoint.Y - tempEndPoint.Y));
Invalidate(Rect);
}
// Draw Area
//
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Draw the rectangle...
if (pictureBox1.Image != null)
{
Brush brush = new SolidBrush(Color.FromArgb(128, 72, 145, 220));
e.Graphics.FillRectangle(brush, Rect);
}
}
Quindi si desidera creare una casella di selezione su un'immagine in una pictureBox? La casella di selezione funzionerà come facendo clic e trascinando sul desktop per creare un quadrato blu trasparente? – 3aw5TZetdf