473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1816
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
3503
by: Merlin | last post by:
Hi Been reading the GOF book and started to make the distinction between Class and Interface inheritance. One question though: Do pure abstract classes have representations? (data members?)...
14
2334
by: Tony Johansson | last post by:
Hello Experts! Assume I have a class called SphereClass as the base class and a class called BallClass that is derived from the SphereClass. The copy constructor initialize the left hand object...
121
9905
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
2
1459
by: Niklas Norrthon | last post by:
I want to share a technique I recently have found to be useful to get around some obstacles that data protection can raise. Consider the following class: // foo.h #ifndef H_FOO #define H_FOO...
1
831
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
0
2192
by: tccode97 | last post by:
To whom it may concern, I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
3
1830
by: lars.uffmann | last post by:
Hi everyone! I am debugging a big piece of code on the search for memory leaks, using g++ under suse 9.3. Since I'm trying to eliminate ALL memory leaks, I now stumbled upon a class foo that is...
1
8547
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
1
4065
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
6
3202
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, can someone please let me know how I can read xml elements using object oriented program. I created a class to use the get and set properties however I dont know how I can pass the values from...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.