paoloTheCool

hmmm....im tring to create a pen feature in my application, to no avail (thus, i am posting) Smile

here is the code i am using:

private void Form1_MouseMove(object sender, MouseEventArgs e)

{

x1 = e.X;

y1 = e.Y;

bt = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);

Graphics g = Graphics.FromImage(bt);

g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2); //draw whatever you want into the bitmap

g.Dispose();

g = this.CreateGraphics();

x2 = e.X;

y2 = e.Y;

this.Invalidate();

}

I want the form to STORE what ive already created....with the code above, i can see the little black likes trailing the mouse, but it doesnt save.... Sad

thanks,

paoloTheCool



Re: Visual C# Express Edition Paint feature Pen

jrboddie

paoloTheCool,

First, I believe that your code for drawing should be inside a paint event. Second, I think you need to establish your starting point (x1, y1) with a mouse down event.

As written, when the mouse moves a small amount, you are drawing a small line segment and then causing the form to redraw thereby erasing what you have previously drawn.

I have put together what you might use as a "paint application starter kit". See if you can download the application here:

http://groups.google.com/group/csharpfun/





Re: Visual C# Express Edition Paint feature Pen

Chris Dunaway

Also, visit this site. It should be helpful:

http://www.bobpowell.net/faqmain.htm






Re: Visual C# Express Edition Paint feature Pen

paoloTheCool

I downloaded your starter kit, and i see what you mean, but this draws lines, (what im trying to do is recreate the feature in MS Paint the "Pencil" or "Pen" where you can just push your left mouse button and draw.

thanks,

paoloTheCool





Re: Visual C# Express Edition Paint feature Pen

paoloTheCool

ok so i have

private void panel1_MouseMove(object sender, MouseEventArgs e)

{

x2 = e.X;

y2 = e.Y;

if (mouseDown)

{

x2 = e.X;

y2 = e.Y;

tempDraw = (Bitmap)snapshot.Clone();

Graphics g = Graphics.FromImage(tempDraw);

Pen myPen = new Pen(Color.Transparent, 4);

g.DrawLine(myPen, x1, y1, x2, y2);

tempDraw.SetPixel(x2, y2, Color.Blue);

myPen.Dispose();

g.Dispose();

x2 = e.X;

y2 = e.Y;

panel1.Invalidate();

panel1.Update();

snapshot = (Bitmap)tempDraw.Clone();

}

}

and it kinda does it, but it leaves a lot of spaces in bewtween. (:-/)





Re: Visual C# Express Edition Paint feature Pen

jrboddie

I have updated the paint application starter kit at http://groups.google.com/group/CSharpFun

It now

  • Draws lines and rectangles
  • Draws free form (Pencil)
  • Allows choice of colors
  • Allows choice of line widths

I hope this helps.





Re: Visual C# Express Edition Paint feature Pen

paoloTheCool

K thanks!! Smile

paoloTheCool