Using the pen class - Questions

  • Thread starter Thread starter Tobias Froehlich
  • Start date Start date
T

Tobias Froehlich

Hello,

I'd like to create a drawing field on a form in which I can draw
(using the Pen class I guess). I've found tutorials on how to use the
GDI+ but I still haven't found out how to actually create a BOX (with
a specified size) in which the user can draw (he shouldn't be able to
draw on the whole form / window!). I will also need to be able to get
information on the drawn pixels in that box (specifically: i need to
draw a rectangular around a letter the user draws and copy that letter
into a smaller box.. comprimized to 10x10 pixels). Can anyone help me
to get on the right track doing that? Or maybe does someone have a
link to a suitable tutorial or even sample files?

i'd be really really thankful for any help!


greetings,

Tobias F.
 
Tobias,

First, you should create a separate control for this. This will allow
you to handle the user not being able to draw outside of the control. Then
you would add your control onto the form.

To create a Box, you would use the DrawRectangle method on the Graphics
object. You would have to override the OnPaint method of your control and
then draw the rectangle if appropriate. The OnPaint method is like a state
machine. When the state of your control changes, you change the state
information stored in the object and then call Invalidate. This will
trigger a repaint. Once you have that, your OnPaint method should paint the
control according to the current state of the control.

Hope this helps.
 
Thanks for your help.. but actually I still have questions :)

I'm a C# beginner.. how do I create a control in VS.NET? And with the
box i just meant a field for the user to draw in.. is that what you
described?
 
Back
Top