469,628 Members | 1,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

Pen / Drawing Field

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.
Nov 15 '05 #1
5 2212
T.F.
You may want to start with this article:

http://msdn.microsoft.com/library/de...ignsurface.asp

Also you may want to look at the Scribble sample included with VS.NET.

Hope this helps
Jay

"T. F." <re*******@gmx.net> wrote in message
news:um********************************@4ax.com...
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.

Nov 15 '05 #2
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/ru...asp#xx414104xx
and a slightly different C# version on the same page
http://www.codeproject.com/dotnet/ru...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/de...ignsurface.asp

Hope all of this helps. Sounds like an interesting project.

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"T. F." <re*******@gmx.net> wrote in message
news:um********************************@4ax.com...
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.

Nov 15 '05 #3
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..).
Nov 15 '05 #4
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?
Nov 15 '05 #5
Look at docs for these two classes:

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

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"T. F." <re*******@gmx.net> wrote in message
news:62********************************@4ax.com...
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?

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Champika Nirosh | last post: by
2 posts views Thread by Josema | last post: by
2 posts views Thread by Vishruth Ranjit | last post: by
9 posts views Thread by davetelling | last post: by
2 posts views Thread by ThatsIT.net.au | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.