Create an outline area

C

citytroop

Hi I am creating a form for vieweing and editing faxes. I read the fax
tiff file into the picturebox. And I have two problems:


1.I want to add a function for the users to be able to select an area
in the picture box and clear it. I am using the Graphics.DrawRectangle
method but the rectangle stays behind the cursor when is moved quickly
eventhough it does draw when releasing the mouse. In the code below I
have the methods used.
2. I would also to create an erase tool like the one in paint any ideas

on how to implement this?


private void peImage_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
//Check if cursor is cross
if(this.peImage.Cursor ==
System.Windows.Forms.Cursors.Cross )
{
//Checks if its left mouse button
if(e.Button == MouseButtons.Left )
{
structDown = new Point(e.X,
e.Y);
structMoveOld.X = e.X;
structMoveOld.Y = e.Y;
blMouseDown = true;
blEndRePaint = true;
}
}
}


private void peImage_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
blEndRePaint = false;
//Check if cursor is cross
if(this.peImage.Cursor ==
System.Windows.Forms.Cursors.Cross )
{
//Checks if its left mouse button
if(e.Button == MouseButtons.Left )
{
structUp = new Point(e.X,
e.Y);
}
}
// Create pen.
Pen blackPen = new Pen(Color.Black);
System.Drawing.SolidBrush sbrushWhite = new
SolidBrush(Color.White);
// Create location and size of rectangle.
int intRectWidth = structUp.X - structDown.X;
int intRectHeight = structUp.Y - structDown.Y;


blMouseDown = false;
structUp.X = 0;
structUp.Y = 0;
// Draw rectangle to screen.
//Need to fill with a brush
Graphics g = this.peImage.CreateGraphics();
g.DrawRectangle(blackPen, structDown.X,
structDown.Y, e.X -
structDown.X, e.Y - structDown.Y);
g.Dispose();


}


private void peImage_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(this.peImage.Cursor ==
System.Windows.Forms.Cursors.Cross &&
blMouseDown == true)
{
if(blEndRePaint == true)
{
if(structMoveOld.X > e.X &&
structMoveOld.Y > e.Y)
{
//Making Smaller


//Delete the vertical
leftovers

this.peImage.Invalidate(new Rectangle(structMoveOld.X+1 ,
structDown.Y, -(structMoveOld.X -e.X), e.Y));
//Delete the vertical
leftovers

this.peImage.Invalidate(new Rectangle(structDown.X ,
structMoveOld.Y+1, e.X, -(structMoveOld.Y -e.Y) ));
blRepaint = true;

this.peImage.Invalidate(new Rectangle(e.X , e.Y, -
(structMoveOld.X -e.X), - (structMoveOld.Y -e.Y)));
//Console.Write("Old X:
" + structUp.X.ToString() + " New X: " +
e.X.ToString() + "\r\n");
}
else if(structMoveOld.X < e.X
&& structMoveOld.Y < e.Y)
{
//Growing
blRepaint = true;

this.peImage.Invalidate(new Rectangle(structDown.X+1,
structDown.Y+1, e.X - structDown.X-1, e.Y - structDown.Y-1));
//Console.Write("Incr
Old X: " + structDown.X.ToString() + " Incr
New X: " + e.X.ToString() + "\r\n");
}
structMoveOld.X = e.X;
structMoveOld.Y = e.Y;

//Console.WriteLine("MouseMove");
}
}


}


private void peImage_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if(blRepaint == true)
{
Pen blackPen = new Pen(Color.Red);
blackPen.DashStyle =
System.Drawing.Drawing2D.DashStyle.DashDotDot;
Graphics g =
this.peImage.CreateGraphics();
g.DrawRectangle(blackPen, structDown.X,
structDown.Y,
structMoveOld.X - structDown.X, structMoveOld.Y - structDown.Y);
g.Dispose();
//Console.WriteLine("ImagePaint");
}
blRepaint = false;
}


Thanks in advance for the help
 
C

citytroop

I found the solution to my first problem is mentioned in the MSDN help
and its and article titled:
HOW TO: Draw a Rubber Band Rectangle or Focus Rectangle in Visual C#
..NET

I would still appreciate help on the second issue though
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top