我怎么画画 [英] How can I draw a picture
本文介绍了我怎么画画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何绘制图片?我什么都找不到?
我从哪里开始?
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方法使用参数(Rectangle
或Region
)仅使控件的一部分无效.无效后,将触发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 methodSystem.Windows.Forms.Control.OnPaint
or handle eventControl.OnPaint
; in both case use the instance of the classSystem.Drawing.Graphics
passed in event arguments in both cases. The control can be aSystem.Windows.Forms.Form
or any other control, such asSystem.Windows.Forms.Panel
. You can do it in the custom control created by subclassingSystem.Windows.Forms.Control
(typically).
Please pay attention: the common mistake is creating an instance of the classSystem.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 callControl.Invalidate
. To improve performance, you can used overloaded Invalidate methods with parameters (Rectangle
orRegion
) 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 methodOnPaint
and then your handlers ofPaint
event if you provide any.
—SA
这篇关于我怎么画画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文