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()
?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Whenever a
Paint
event is raised, you are given aGraphics
object to draw into. This is passed aspevent.Graphics
. Drawing into thisGraphics
object is how you paint the element.CreateGraphics
should basically never be used. It creates a newGraphics
object on-the-fly from a window handle. You can draw into theGraphics
object it returns, but anything you draw into it will be obliterated the next time that aPaint
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 useCreateGraphics
to get a temporary canvas to draw onto while the drag event is in progress.You will never use
CreateGraphics
inside of aPaint
event handler method. There is no point—you are given aGraphics
object to draw into already!