Microsoft Paint functionality in C#

S

Scott

I am looking for some simple code samples in C# that emulates
Microsoft Paint. There is the .NET Paint program but that code sample
is fairly complex. I need to be able to load a picture and then draw
ink on that picture using the pen, rectangle, ellipse, etc. Anyone
know of a some sample code to get me started with other than just the
basic DrawEllipse method where I have to pass it a coordinate
everytime the mouse moves. Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Scott,

I am not sure what you are looking for really. In essence, that is
really what you have to do when you want to draw things like rectangles,
ellipses, etc, etc.

For drawing with a pen, you just have to keep track of the mouse
movements while the button is down. You basically would keep track of each
point that the mouse is at while it moves, and then draw a line from the
last point to the current point using the selected pen.

For drawing rectangles and ellipses, the procedure is pretty much the
same. You would store the initial point where the button was clicked, and
store the location of the last point that the mouse moved on as well. As
the mouse moves, you would have to "erase" the last rectangle you drew (if
anything, you might want to store the image bits, or xor the
rectangle/ellipse over the image, so you can easily reverse the operation),
and then draw a new one. When you release the mouse, you would leave the
rectangle as it is.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top