System::Windows::Forms::PaintEventArgs ^ pe) Void Form1_Paint(System::Object ^ sender, Declares the Graphics object and sets it to the Graphics object ' Declares the Graphics object and sets it to the Graphics object
The following example shows how to reference a Graphics object from the PaintEventArgs in the Paint event: Private Sub Form1_Paint(sender As Object, pe As PaintEventArgs) Handles _
Insert code to paint the form or control. To obtain a reference to a Graphics object from the PaintEventArgs in the Paint eventĪssign the variable to refer to the Graphics object passed as part of the PaintEventArgs. When programming the PaintEventHandler for controls or the PrintPage for a PrintDocument, a graphics object is provided as one of the properties of PaintEventArgs or PrintPageEventArgs. PaintEventArgs in the Paint Event Handler The following sections give details about each of these processes. This approach is useful when you want to alter an already existing image. Use this method if you want to draw on a form or control that already exists.Ĭreate a Graphics object from any object that inherits from Image. Similarly, you can also obtain a graphics object as a property of the PrintPageEventArgs when handling the PrintPage event for a PrintDocument.Ĭall the CreateGraphics method of a control or form to obtain a reference to a Graphics object that represents the drawing surface of that control or form.
This is usually how you obtain a reference to a graphics object when creating painting code for a control. Receive a reference to a graphics object as part of the PaintEventArgs in the Paint event of a form or control. Using the Graphics object to draw lines and shapes, render text, or display and manipulate images.Ī graphics object can be created in a variety of ways. There are two steps in working with graphics: The Graphics object represents a GDI+ drawing surface, and is the object that is used to create graphical images. Before you can draw lines and shapes, render text, or display and manipulate images with GDI+, you need to create a Graphics object.