Retrieving a Graphics Object

Within a form or control’s paint event, you can retrieve and use a Graphics object instance. The paint event handler takes a PaintEvent object as a parameter, and this object contains a public graphics member. This member is a valid Graphics object instance, which you call as follows:

protected void onPaint(PaintEvent e){
   e.graphics.drawString("Hello, World", new Point(10, 10));
}

For information on how to create a Graphics object outside the paint event, see Explicit Graphics Object Creation and Implicit Graphics Object Creation.