Drawing with Graphics class in C#

心已入冬 提交于 2019-12-12 15:10:37

问题


I would like to draw in C# with the mouse, like if the mouse were a pen. I am trying with Graphics class, using DrawLines method receiving an array of points as parameter.

Do you think this is the better option, or do yo know if is there another easy way to do it?

Thanks in advance

Regards.


回答1:


Look at this sample:

http://www.codeproject.com/KB/graphics/drawtools.aspx

Specifically, the Pencil tool does what you need.




回答2:


You have to use a combination of the MouseMove, MouseDown, and MouseUp events. MouseDown and MouseUp will set and clear a flag telling you the user is holding down the button. While this flag is set, any MouseMove events should result in a line being drawn from the last known mouse position to the new one (a LOT of MouseMove events can be fired in this way, so I would check VERY quickly to make sure you actually needed to do something, and it might be a good idea to make the handler single-threaded using locking).



来源:https://stackoverflow.com/questions/3805437/drawing-with-graphics-class-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!