Pen / Drawing Field

  • Thread starter Thread starter T. F.
  • Start date Start date
T

T. F.

Hi,

I need to create a box / field that the user can draw into (with some
kind of pen). I also need to know how I can edit the size of the pen
style and how I can "transport" the drawn image into a
smaller box (that is only around 10x10 pixel so the original image
must be comprimized onto that 10x10 pixel field..) and how to center
it. ( if you guess that this is about neural networks you're right :)
)

THANKS A LOT for any help.
 
See the System.Drawing namespace

Look at the System.Drawing.Pen class for the pens that you can set color /
width.
ControlPaint.DrawReversibleLine for the drawing

Handle the mousedown, mousemove and mouseup events as needed to draw lines.
There's an article on codeproject that has some good reader comments:
(in vb.net)
http://www.codeproject.com/dotnet/rubberbandline.asp#xx414104xx
and a slightly different C# version on the same page
http://www.codeproject.com/dotnet/rubberbandline.asp#xx559274xx

Then you'll want to reconstruct the drawn lines onto an image object. I
suggest you keep an arraylist in memory of each line as it is drawn
(possibly a rectangleF struct or some other object of two points). Then
when you want to resize, create a Bitmap object (System.Drawing.Imaging
namespace) and redraw all the lines onto it. Then you can draw this new
image onto the control using Graphics.DrawImage function (this has plenty of
overloads to assist with reducing size). (see
http://www.bobpowell.net/faqmain.htm for more GDI+ tips)

For more details on drawing directly to a picturebox, check out this
article:
http://www.bobpowell.net/pictureboxhowto.htm

Here are some articles on allowing the user to draw, but this is a bit more
involved than what you need. And it is in vb.net, but it should give you
some ideas
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/designsurface.asp

Hope all of this helps. Sounds like an interesting project.
 
Thanks a lot, both of you!

The project is interesting but nothing special; it's a pattern
recognition program where a neural network recognizes letters which
the user writes into a box (one of the "standard" examples of neural
networks..).
 
Oh and btw, i don't need to draw lines, i just need the pen. Is that a
seperate class or do i also need to use
ControlPaint.DrawReversibleLine?
 
Look at docs for these two classes:

System.Drawing.Graphics
System.Drawing.Pen
(yes pen is a separate class)
 
Back
Top