private void pictureCrop_MouseUp(object sender, MouseEventArgs e)
{
//Quite a work with this thing huh...
if (e.Button != MouseButtons.Left)
return;
if (e.X > _posX && e.Y > _posY)
{
_width = Math.Abs(e.X - _posX);
_height = Math.Abs(e.Y - _posY);
}
else if (e.X < _posX && e.Y < _posY)
{
_width = Math.Abs(_posX - e.X);
_height = Math.Abs(_posY - e.Y);
_posX = e.X;
_posY = e.Y;
}
else if (e.X < _posX && e.Y > _posY) // top right to bottom left
{
_width = Math.Abs(_posX - e.X);
_height = Math.Abs(_posY - e.Y);
_posX = e.X;
}
else if (e.X > _posX && e.Y < _posY) //bottom left to top right
{
_width = Math.Abs(_posX - e.X);
_height = Math.Abs(_posY - e.Y);
_posY = e.Y;
}
else if (e.X == _posX && e.Y == _posY)
{
this.Text = Resources.Title_CropNoSelection;
tbHeight.Text = "0";
tbWidth.Text = "0";
_width = 0;
_height = 0;
_g.DrawImage(_bitmap, 0, 0);
return;
}
if (_posX + _width > pictureCrop.Size.Width)
_width = pictureCrop.Size.Width - _posX;
if (_posY + _height > pictureCrop.Size.Height)
_height = pictureCrop.Size.Height - _posY;
if (_posX < 0)
{
_width = _width - Math.Abs(_posX);
_posX = 0;
}
if (_posY < 0)
{
_height = _height - Math.Abs(_posY);
_posY = 0;
}
this.Text = Resources.Title_Crop;
tbWidth.Text = _width.ToString();
tbHeight.Text = _height.ToString();
_g.DrawImage(_bitmap, 0, 0);
Rectangle = new Rectangle(_posX, _posY, _width, _height);
_g = pictureCrop.CreateGraphics();
_g.DrawRectangle(_pen, Rectangle);
}