System.Drawing.Graphics Class

Encapsulates a ndptecgdiplus drawing surface. This class cannot be inherited.

See Also: Graphics Members

Syntax

public sealed class Graphics : MarshalByRefObject, IDeviceContext

Remarks

The System.Drawing.Graphics class provides methods for drawing objects to the display device. A System.Drawing.Graphics is associated with a specific device context.

You can obtain a System.Drawing.Graphics object by calling the System.Windows.Forms.Control.CreateGraphics method on an object that inherits from System.Windows.Forms.Control, or by handling a control's System.Windows.Forms.Control.Paint event and accessing the System.Windows.Forms.PaintEventArgs.Graphics property of the System.Windows.Forms.PaintEventArgs class. You can also create a System.Drawing.Graphics object from an image by using the Graphics.FromImage(Image) method. For more information about creating a System.Drawing.Graphics object, see How to: Create Graphics Objects for Drawing.

You can draw many different shapes and lines by using a System.Drawing.Graphics object. For more information about how to draw lines and shapes, see the specific DrawGraphicalElement method for the line or shape you want to draw. These methods include Graphics.DrawLine(Pen, Point, Point), Graphics.DrawArc(Pen, Rectangle, float, float), Graphics.DrawClosedCurve(Pen, PointF[]), Graphics.DrawPolygon(Pen, PointF[]), and Graphics.DrawRectangle(Pen, Rectangle). For more information about how to draw lines and shapes, see Using a Pen to Draw Lines and Shapes and Using a Brush to Fill Shapes.

You can also draw images and icons by using the Graphics.DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, System.Drawing.Imaging.ImageAttributes, System.Drawing.Graphics.DrawImageAbort) and Graphics.DrawIcon(Icon, Rectangle) methods, respectively. To perform a bit-block transfer of color data from the screen to the drawing surface of the System.Drawing.Graphics object, see Graphics.CopyFromScreen(Point, Point, Size). For more information about how to draw images with a System.Drawing.Graphics object, see Working with Images, Bitmaps, Icons, and Metafiles.

In addition, you can manipulate the coordinate system used by the System.Drawing.Graphics object. For more information on the coordinate system and how to manipulate it, see Coordinate Systems and Transformations.

Requirements

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0