المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : System.Drawing.Graphics Problem



C# Programming
01-17-2010, 08:10 AM
Hi All,

Its been quite a long time since I am stuck with this problem. I am writing an application in which user selects a portion of picture box and rest part (apart from selection) is filled with white color.

Now Problem is that FillRectange fill area more that what is selected. For example here is code to fill from 0,0 of image to first node of rectangular selection:

private void picItem_MouseDown(object sender, MouseEventArgs e)
{
// Starting point of the selection:
if (e.Button == MouseButtons.Left)
{
_selecting = true;
_selection = new Rectangle(new Point(e.X, e.Y), new Size());
}
}

private void picItem_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && _selecting)
{
Rectangle cropRect = _selection;

using (Graphics g = Graphics.FromImage(picItem.Image))
{
g.FillRectangle(Brushes.White, new Rectangle(0, 0, _selection.X, _selection.Y));
}

picItem.*******();
_selecting = false;
}
}

private void picItem_MouseMove(object sender, MouseEventArgs e)
{
// Update the actual size of the selection:
if (_selecting)
{
_selection.Width = e.X - _selection.X;
_selection.Height = e.Y - _selection.Y;

// Redraw the picturebox:
picItem.*******();

lbl********.Text = "Height = " + _selection.Height.ToString() + ", Width = "
+ _selection.Width.ToString();
}
}

Can anyone tell me why this is happening please?