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:

PROPERTIES
Clip Gets or sets a Region that limits the drawing region of this Graphics.
ClipBounds Gets a RectangleF structure that bounds the clipping region of this Graphics.
CompositingMode Gets a value that specifies how composited images are drawn to this Graphics.
CompositingQuality 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.
InterpolationMode Gets or sets the interpolation mode associated with this Graphics.
IsClipEmpty Gets a value indicating whether the clipping region of this Graphics is empty.
IsVisibleClipEmpty Gets a value indicating whether the visible clipping region of this Graphics is empty.
PageScale Gets or sets the scaling between world units and page units for this Graphics.
PageUnit Gets or sets the unit of measure used for page coordinates in this Graphics.
PixelOffsetMode Gets or sets a value specifying how pixels are offset during rendering of this Graphics.
RenderingOrigin Gets or sets the rendering origin of this Graphics for dithering and for hatch brushes.
SmoothingMode Gets or sets the rendering quality for this Graphics.
TextContrast Gets or sets the gamma correction value for rendering text.
TextRenderingHint 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.
VisibleClipBounds Gets the bounding rectangle of the visible clipping region of this Graphics.

References

The Basics of GDI (codemag.com)

GDI+ Tutorial for Beginners (c-sharpcorner.com)

Graphics Class (System.Drawing) | Microsoft Docs

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.