CreateGraphics和Paint事件的Graphics对象有什么区别? [英] What is the difference between CreateGraphics and a Paint event's Graphics object?

查看:240
本文介绍了CreateGraphics和Paint事件的Graphics对象有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释作为 pevent.Graphics 传递的图形对象与通过调用返回 this.CreateGraphics()

解决方案

每当一个 Paint 事件被引发,给你一个 Graphics 对象来绘制。这是作为 pevent.Graphics 传递的。绘制到这个 Graphics 对象中就是绘制元素的方式。

CreateGraphics 。它从窗口句柄中即时创建一个新的 Graphics 对象。您可以绘制它返回的 Graphics 对象,但是当您下一次绘制 Paint >

您可能想要使用 CreateGraphics 的唯一时间是用于特殊效果,如显示真实拖动过程中的时间反馈。您希望在下一次元素重新绘制时被删除,所以您继续并使用 CreateGraphics 来获取临时画布以绘制到而拖动事件正在进行中。



您不会 使用 CreateGraphics 一个 Paint 事件处理程序方法。没有意义 - 你得到一个 Graphics 对象来绘制已经!


Can someone explain the difference between the Graphics object that is passed as pevent.Graphics and the one that is returned by a call to this.CreateGraphics()?

解决方案

Whenever a Paint event is raised, you are given a Graphics object to draw into. This is passed as pevent.Graphics. Drawing into this Graphics object is how you paint the element.

CreateGraphics should basically never be used. It creates a new Graphics object on-the-fly from a window handle. You can draw into the Graphics object it returns, but anything you draw into it will be obliterated the next time that a Paint event is raised.

The only time you might want to use CreateGraphics is for special effects, like showing real-time feedback during a drag. You want that to be erased the next time that the element is repainted, so you go ahead and use CreateGraphics to get a temporary canvas to draw onto while the drag event is in progress.

You will never use CreateGraphics inside of a Paint event handler method. There is no point—you are given a Graphics object to draw into already!

这篇关于CreateGraphics和Paint事件的Graphics对象有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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