J
James Dean
I know what you mean about using invalidate and i have already just
cleared the graphics object and set it to the back Color. The problem is
that i want to keep these lines, ellipses or rectangles i have drawn on
the screen so i just draw the image to an offscreen bitmpa but the next
time i want to draw another image on top of this the backcolor clears
and i lose the shape i had drawn to the bitmap previously......i know i
can just use the mouseup......but i want to see the image as being
drawn......here is the code
public Main_Form()
{
raphicsObject = this.CreateGraphics();
graphicsObject.PageUnit = GraphicsUnit.Pixel;
offScreenBmp = new Bitmap(this.Width, this.Height);
Graphics OffScreenGraphics = Graphics.FromImage(offScreenBmp);
OffScreenGraphics.DrawImage(offScreenBmp,0,0);
}
private void Main_Form_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
startatX = e.X;
startatY = e.Y;
shouldPaint = true;
}
private void Main_Form_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(shouldPaint)
{
PaintToScreen1(e.X, e.Y);
}
}
private void PaintToScreen1(int x, int y)
{
Pen pen = new Pen(Color.DarkBlue);
int MouseX = x;
int MouseY = y;
int width = MouseX - startatX;
int height = MouseY - startatY;
if(LineMenuItem.Checked == true)
{
graphicsObject.DrawLine(pen,startatX,startatY,x,y);
}
else if(EllipseMenuItem.Checked == true)
{
graphicsObject.DrawEllipse(pen,startatX,startatY,width,height);
}
else if(RectMenuItem.Checked == true)
{
graphicsObject.DrawRectangle(pen,startatX,startatY,width,height);
}
}
private void Main_Form_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
shouldPaint = false;
Pen newpen = new Pen(Color.Gray,0);
graphicsObject = temporaryGraphicsObject;
graphicsObject.DrawImage(offScreenBmp,0,0);
}
In the PaintScreen method if i put
graphicsObject.Clear(this.BackColor)......then it will erase the
previous shape i have drawn on the screen......hope u can help
cleared the graphics object and set it to the back Color. The problem is
that i want to keep these lines, ellipses or rectangles i have drawn on
the screen so i just draw the image to an offscreen bitmpa but the next
time i want to draw another image on top of this the backcolor clears
and i lose the shape i had drawn to the bitmap previously......i know i
can just use the mouseup......but i want to see the image as being
drawn......here is the code
public Main_Form()
{
raphicsObject = this.CreateGraphics();
graphicsObject.PageUnit = GraphicsUnit.Pixel;
offScreenBmp = new Bitmap(this.Width, this.Height);
Graphics OffScreenGraphics = Graphics.FromImage(offScreenBmp);
OffScreenGraphics.DrawImage(offScreenBmp,0,0);
}
private void Main_Form_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
startatX = e.X;
startatY = e.Y;
shouldPaint = true;
}
private void Main_Form_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(shouldPaint)
{
PaintToScreen1(e.X, e.Y);
}
}
private void PaintToScreen1(int x, int y)
{
Pen pen = new Pen(Color.DarkBlue);
int MouseX = x;
int MouseY = y;
int width = MouseX - startatX;
int height = MouseY - startatY;
if(LineMenuItem.Checked == true)
{
graphicsObject.DrawLine(pen,startatX,startatY,x,y);
}
else if(EllipseMenuItem.Checked == true)
{
graphicsObject.DrawEllipse(pen,startatX,startatY,width,height);
}
else if(RectMenuItem.Checked == true)
{
graphicsObject.DrawRectangle(pen,startatX,startatY,width,height);
}
}
private void Main_Form_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
shouldPaint = false;
Pen newpen = new Pen(Color.Gray,0);
graphicsObject = temporaryGraphicsObject;
graphicsObject.DrawImage(offScreenBmp,0,0);
}
In the PaintScreen method if i put
graphicsObject.Clear(this.BackColor)......then it will erase the
previous shape i have drawn on the screen......hope u can help