I draw a rectangle on the frame with mouse events:
private void StreamingWindow_MouseDown(object sender, MouseEventArgs e)
{
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
}
private void StreamingWindow_Paint(object sender, PaintEventArgs e)
{
if (painting == true)
{
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}
}
private void StreamingWindow_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
}
this.Invalidate();
}
After drawing the rectangle, I can grab it inside and save as jpg.
What is my problem?
I can draw an edge whose borders are outside the image area:

How can I limit the area of a rectangle whose border is the maximum allowable location of the rectangle?
Sorry for my English, I hope you understand my problem :) Therefore, I would like to have something like this:

Elfoc source
share