471,108 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Using the pen class - Questions

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.
Nov 15 '05 #1
3 1723
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.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Tobias Froehlich" <re*******@gmx.net> wrote in message
news:cl********************************@4ax.com...
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.

Nov 15 '05 #2
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?

Nov 15 '05 #3
Tobias,

You would have to derive a class from the Control class in the
System.Windows.Forms namespace. Check out the section of the .NET framework
documentation titled "Developing Windows Forms Controls", located at (watch
for line wrap):

http://msdn.microsoft.com/library/de...mscontrols.asp
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Tobias Froehlich" <re*******@gmx.net> wrote in message
news:jh********************************@4ax.com...
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?

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Merlin | last post: by
14 posts views Thread by Tony Johansson | last post: by
121 posts views Thread by typingcat | last post: by
2 posts views Thread by Niklas Norrthon | last post: by
6 posts views Thread by =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.