In graphical user interfaces such as Microsoft Windows, drawing on the screen is an important task.
Everything displayed on the screen is based on simple drawing operations. In Visual Studio .NET, developers have easy access to that drawing functionality whenever they need it through a technology called GDI+. Using GDI+, developers can easily perform drawing operations such as generating graphs or building custom controls.
All GDI+ drawing is done using a Graphics object. This object has a large number of methods that encapsulate drawing operations on a drawing “canvas.” GDI+ supports some drawing canvases including windows, bitmaps, and printer pages. Depending on the type of drawing canvas, the Graphics object is created or retrieved in several different ways. If you want to modify the contents of a bitmap file you would create a Bitmap canvas using the FromImage() method.
Drawing in a WinForms form is a somewhat peculiar task because it is not enough to draw the graphic once. Instead, the “drawing” may have to be “refreshed” (re-drawn) whenever a window requires repainting. Repainting can happen whenever a user resizes a window or one window overlaps another window and then something brings the overlapped windows to the front.
Whenever you use GDI+ to draw, you use the GDI+ coordinate system. By default, the coordinate system maps directly to the pixels on your monitor. However, you may want different behaviour. You can transform the coordinate system if you have special needs.
Graphics class’s methods:
| DrawArc | Draws an arc from the specified ellipse. |
| DrawBezier | Draws a cubic bezier curve. |
| DrawBeziers | Draws a series of cubic Bezier curves. |
| DrawClosedCurve | Draws a closed curve defined by an array of points. |
| DrawCurve | Draws a curve defined by an array of points. |
| DrawEllipse | Draws an ellipse. |
| DrawImage | Draws an image. |
| DrawLine | Draws a line. |
| DrawPath | Draws the lines and curves defined by a GraphicsPath. |
| DrawPie | Draws the outline of a pie section. |
| DrawPolygon | Draws the outline of a polygon. |
| DrawRectangle | Draws the outline of a rectangle. |
| DrawString | Draws a string. |
| FillEllipse | Fills the interior of an ellipse defined by a bounding rectangle. |
| FillPath | Fills the interior of a path. |
| FillPie | Fills the interior of a pie section. |
| FillPolygon | Fills the interior of a polygon defined by an array of points. |
| FillRectangle | Fills the interior of a rectangle with a Brush. |
| FillRectangles | Fills the interiors of a series of rectangles with a Brush. |
| FillRegion | Fills the interior of a Region. |
Graphics class’s properties:
| Clip | Gets or sets a Region that limits the drawing region of this Graphics. |
| Clip |
Gets a RectangleF structure that bounds the clipping region of this Graphics. |
| Compositing |
Gets a value that specifies how composited images are drawn to this Graphics. |
| Compositing |
Gets or sets the rendering quality of composited images drawn to this Graphics. |
| DpiX | Gets the horizontal resolution of this Graphics. |
| DpiY | Gets the vertical resolution of this Graphics. |
| Interpolation |
Gets or sets the interpolation mode associated with this Graphics. |
| Is |
Gets a value indicating whether the clipping region of this Graphics is empty. |
| Is |
Gets a value indicating whether the visible clipping region of this Graphics is empty. |
| Page |
Gets or sets the scaling between world units and page units for this Graphics. |
| Page |
Gets or sets the unit of measure used for page coordinates in this Graphics. |
| Pixel |
Gets or sets a value specifying how pixels are offset during rendering of this Graphics. |
| Rendering |
Gets or sets the rendering origin of this Graphics for dithering and for hatch brushes. |
| Smoothing |
Gets or sets the rendering quality for this Graphics. |
| Text |
Gets or sets the gamma correction value for rendering text. |
| Text |
Gets or sets the rendering mode for text associated with this Graphics. |
| Transform | Gets or sets a copy of the geometric world transformation for this Graphics. |
| Visible |
Gets the bounding rectangle of the visible clipping region of this Graphics. |
References
The Basics of GDI (codemag.com)




Leave a Reply
Want to join the discussion?Feel free to contribute!