What is the difference between CreateGraphics and a Paint event's Graphics object?

前端 未结 1 1651
星月不相逢
星月不相逢 2021-01-29 15:33

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.C

相关标签:
1条回答
  • 2021-01-29 16:16

    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!

    0 讨论(0)
提交回复
热议问题