Question

I wrote this code:

private void ResizeImage()
{
    SetImage(Image);
}

private void SetPen()
{
    CreatePen(10,10,20,60);
}

private void CreatePen(int x, int y, int width, int height)
{
    Rectangle = new Rectangle(x, y, width, height);
    Pen = new Pen(Color.Crimson, 1);
    (Image.CreateGraphics()).DrawRectangle(Pen, Rectangle);
    Invalidate();
}

The problem is that the method Load() replaces image to rectangle. I'm doing image Cropper, where the user can not create new selection. The program creates the selection itself, the user can only move it.

Was it helpful?

Solution

In Paint event of PictureBox draw your rectangle:

void PictureBox_Paint(object sender, PaintEventArgs e)
{
    Rectangle = new Rectangle(x, y, width, height);
    Pen = new Pen(Color.Crimson, 1);
    e.Graphics.DrawRectangle(Pen, Rectangle);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top