我怎么画画 [英] How can I draw a picture

查看:116
本文介绍了我怎么画画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制图片?我什么都找不到?
我从哪里开始?

How can I draw a picture? I can''t find anything?
Where can I start?

Thanks in advance!

推荐答案

我想你不是在问静态图片,而是在运行时画图.

您应该使用覆盖的方法System.Windows.Forms.Control.OnPaint或处理事件Control.OnPaint;在这两种情况下,都使用在事件参数中传递的类System.Drawing.Graphics的实例.该控件可以是System.Windows.Forms.Form或任何其他控件,例如System.Windows.Forms.Panel.您可以在通过子类化System.Windows.Forms.Control创建的自定义控件中进行此操作(通常).

请注意:常见的错误是使用类System.Drawing.Graphics的构造函数创建实例.您不应该这样做(根据经验);实例已在上述方法的参数中提供.

如果您需要修改图形(需要动画或只是为了反映更改后的状态.在这种情况下,您需要更改用于渲染的数据并调用Control.Invalidate.要提高性能,可以使用重载的Invalidate方法使用参数(RectangleRegion)仅使控件的一部分无效.无效后,将触发WM_PAINT Windows消息,这将导致调用渲染方法OnPaint,然后调用Paint事件(如果提供).

—SA
I assume you''re asking not about static picture but about drawing during run-time.

You should use overridden method System.Windows.Forms.Control.OnPaint or handle event Control.OnPaint; in both case use the instance of the class System.Drawing.Graphics passed in event arguments in both cases. The control can be a System.Windows.Forms.Form or any other control, such as System.Windows.Forms.Panel. You can do it in the custom control created by subclassing System.Windows.Forms.Control (typically).

Please pay attention: the common mistake is creating an instance of the class System.Drawing.Graphics using its constructor. You should not do it (as a rule of thumb); the instance is already provided in the arguments of the methods mentioned above.

If you need to modify the graphics (with is need for animation or just to reflect changed state. In this case, you need to changes the data you use for rendering and call Control.Invalidate. To improve performance, you can used overloaded Invalidate methods with parameters (Rectangle or Region) to invalidate just the part of the control. After invalidation, WM_PAINT Windows message will be triggered, which will cause the call of your rendering method OnPaint and then your handlers of Paint event if you provide any.

—SA


这篇关于我怎么画画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆