Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need advise - How to write a drawing program

Tags:

c#

gdi+

I would like to write a program that enable user to draw geometric shapes like circles, triangles, rectangles and so on.

I would like also to be able to drag and drop or resize/move a shape that was previously drawn.

  1. I thought to draw the shapes inside a Panel. Does it seems reasonable ?
  2. After I draw a circle, it becomes a part of a Bitmap. Of course, I do save circle's details in some other object.

But what I don't understand is how to implement the following:

When the mouse is over the circle, the circle is chosen, and then using some key enables the user to resize/move it.

How can I know that the mouse is over the circle ?

Do I need to check the mouse coordinates vs all circle pixel coordinates ?

I'm looking for simpler solution.

like image 504
user240970 Avatar asked Feb 27 '23 20:02

user240970


1 Answers

Use the WPF Graphics and Multi-media. http://msdn.microsoft.com/en-us/library/ms752061.aspx

Windows Presentation Foundation (WPF) includes support for high quality 2-D and 3-D graphics, animation, and media. Key features of the graphic platform include:

Vector graphic support.

Hardware acceleration.

Resolution and device-independent graphics.

Minimal screen redraw and integrated animation system.

It has everything you need - why re-invent the wheel?

You need to keep the objects as graphical objects themselves, so they can respond to mouseover events. Once you put them into a bitmap, then you are going to have to essentially re-invent the wheel.

For example,

Here's shape objects:

http://msdn.microsoft.com/en-us/library/ms747393.aspx#shapes

Here's hit testing:

http://msdn.microsoft.com/en-us/library/ms752097.aspx

You also get the advantage of hardware acceleration, resolution ad device-independent graphics. I don't think you are going to be able to implement this yourself easily :)

like image 131
Larry Watanabe Avatar answered Mar 11 '23 12:03

Larry Watanabe