I have a code with a mouseUp event.
In this event im drawing with the mouse a rectangle inside a picturebox1 on image.
Now the problem is when i draw the rectangle too big so its getting out the borders of hte image or the picturebox1. The thing is its getting out of the borders inside the picturebox1 i just cant see it.
I want that if the rectangle is out of the borders so it will write something...
Now the variables: FirstImage is the image the user select to draw on with fileDialoge.
The variable RectImage is a REctangle wich im using to draw with.
and the line where i want to check the rectangle borders with the picturebox1/or the image borders is:
Now this IF statement isnt right. I cant figure out i tried so much cant figure out what to compare and ho to check that if i draw too much big rectangle it will write.
This is the complete mouseUp event code:
The IF in this code isnt good too.
Thanks.
In this event im drawing with the mouse a rectangle inside a picturebox1 on image.
Now the problem is when i draw the rectangle too big so its getting out the borders of hte image or the picturebox1. The thing is its getting out of the borders inside the picturebox1 i just cant see it.
I want that if the rectangle is out of the borders so it will write something...
Now the variables: FirstImage is the image the user select to draw on with fileDialoge.
The variable RectImage is a REctangle wich im using to draw with.
and the line where i want to check the rectangle borders with the picturebox1/or the image borders is:
Code:
if (newLeft > 0 || newTop > 0)
{
MessageBox.Show("You are out of region!");
return;
}
This is the complete mouseUp event code:
Code:
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
tempBmp = new Bitmap(FirstImage);
float newLeft = ((float)Rect.Left/(float)pictureBox1.Width)*((float)FirstImage.Width);
float newRight = ((float)Rect.Right/(float)pictureBox1.Width)*((float)FirstImage.Width);
float newTop = ((float)Rect.Top/(float)pictureBox1.Height)*((float)FirstImage.Height);
float newBottom = ((float)Rect.Bottom/(float)pictureBox1.Height)*((float)FirstImage.Height);
RectImage = new Rectangle((int)newLeft, (int)newTop, (int)newRight - (int)newLeft, (int)newBottom - (int)newTop);
if (RectImage.Size.Height > FirstImage.Size.Height ) ||
RectImage.Size.Width > pictureBox1.Bounds.Left || RectImage.Width > pictureBox1.Bounds.Right) //bounds are not ok )
{
MessageBox.Show("You are out of region!");
return;
}
int i, j;
for (i=RectImage.Left;i<RectImage.Right;i++)
for (j = RectImage.Top; j < RectImage.Bottom; j++)
{
Color c = FirstImage.GetPixel(i, j);
tempBmp.SetPixel(i, j, c);
}
pictureBox1.Image = tempBmp;
textBox5.Text = "Right " + RectImage.Right + " Bottom " + RectImage.Bottom;
textBox4.Text = "Left " + RectImage.Left + " Top " + RectImage.Top;
if (FirstImage != null && SecondImage != null)
{
if (this._dontDrawRect == false)
{
if (MessageBox.Show("Use this Rectangle for comparing?", "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
System.Windows.Forms.DialogResult.Yes)
{
this._dontDrawRect = true;
}
}
if (_dontDrawRect)
{
if (copy_mode == true)
{
MessageBox.Show("hi");
}
else
{
if (ImagesComparion1.ImageComparison(FirstImage, SecondImage, Rect))
{
textBox1.Text = ImagesComparion1.textbox1;
textBox2.Text = ImagesComparion1.textbox2;
textBox3.Text = ImagesComparion1.textbox3;
MessageBox.Show("identical");
}
else
{
textBox1.Text = ImagesComparion1.textbox1;
textBox2.Text = ImagesComparion1.textbox2;
textBox3.Text = ImagesComparion1.textbox3;
MessageBox.Show("different");
}
}
}
}
}
else if (e.Button == System.Windows.Forms.MouseButtons.Right)
this._dontDrawRect = false;
}
Thanks.
Comment