سؤال

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.

هل كانت مفيدة؟

المحلول

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);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top