selected area to cut an image

Posted by Oskar Marciniak on Stack Overflow See other posts from Stack Overflow or by Oskar Marciniak
Published on 2011-03-06T16:09:21Z Indexed on 2011/03/07 0:10 UTC
Read the original article Hit count: 124

Filed under:
|
|
|

Hi I would do the selected area to cut an image on picturebox control.

I have the following code:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

public partial class Form1 : Form
{
    private Rectangle rect;
    private Pen p;

    public Form1()
    {
        InitializeComponent();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        if (this.p == null)
            this.p = new Pen(Color.FromArgb(100, 200, 200, 200), 5);
        if (this.rect.Width > 0)
            e.Graphics.DrawRectangle(this.p, this.rect);
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {

        if (e.X < this.rect.X)
        {
            this.rect.Width = this.rect.X - e.X;
            this.rect.X = e.X;
        }
        else
        {
            this.rect.Width = e.X - this.rect.X;
        }

        if (e.Y < this.rect.Y)
        {
            this.rect.Height = this.rect.Y - e.Y;
            this.rect.Y = e.Y;
        }
        else
        {
            this.rect.Height = e.Y - this.rect.Y;
        }

        this.Invalidate(this.rect);

    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        this.rect.X = e.X;
        this.rect.Y = e.Y;
    }

}

}

It returns an error here:

Application.Run(new Form1());

Why?

thanks for all replies ;p

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET