So wählen Sie einen Bereich auf einer PictureBox.Bild mit der Maus in C#

wollte ich nur eine Auswahl auf meinem picturebox.Bild das hat aber nur schlimmer geworden, als einige etwas nervige situation. Ich dachte, auf einem anderen Bild-Feld über die wichtigsten picturebox aber es schien so faul Arbeit zu mir. Ich muss wissen, ob es gibt einen Weg, um erstellen Sie einen Auswahlbereich (das ist gonna be eine halb transparente Blaue Fläche) auf einem picturebox-Steuerelement.Bild, das im gonna ziehen mit der Maus, und es sollte nicht ändern Sie die Bild-im-arbeiten.

Beispiel:

    //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);
        }
    }
  • Also willst du zum erstellen einer Auswahl-box auf ein Bild in eine pictureBox? Wird der Auswahl-box handeln das gleiche wie das klicken und ziehen auf dem desktop zu erstellen, eine transparente Blaue Quadrat?
Schreibe einen Kommentar