Monday, April 23, 2007

Introduction to GDI+

GDI+ is a managed class from .NET Framework that provides function for drawing two-dimensional vector graphics, imaging, and typography. GDI stands for Graphical Device Interfaces and include in earlier Windows platform. GDI+ itself is the portion of Windows XP operating system and adding new features and optimized existing features.

GDI+ is one of most important things that you need to know when you're developing Windows Forms Application in .NET Framework, especially when you want to design a rich UI application, creating a customized component or user controls.

The Basics

GDI+ contains of 3 sections which are:

  1. Vector graphics (Lines, Curves and Shapes)
  2. Images, Bitmaps and Metafiles
  3. Coordinates and Transformations

    Note to Visual Basic 6.0 Users: You probably mentioned why there are no Line and Shape in toolbox area. That's because .NET Framework has replaced them with GDI+ function. You have to use GDI+ to drawing line and shape within the code.

GDI+ is a set of calls or procedure. So, in order to use it, you have to call those functions and passing the required parameters. Since you call a function, its effect can only be seen on runtime mode. You can't see them in design mode unlike VB6. Because you can't see anything in design mode, you have to input parameter and placed the coordinates precisely. That's a bit hard at start, but once you've mastered it, it will become very fun to use.

Using GDI+

To use GDI+, you will need Graphics object. Graphics is a managed interface for providing GDI+ functions. GDI+ class contains of these namespace:

  • System.Drawing
  • System.Drawing.Drawing2D
  • System.Drawing.Imaging
  • System.Drawing.Text
  • System.Drawing.Printing

For using them, there are 2 ways which are: Object.CreateGraphics, or in the Paint event. The Paint event is consider a safer way to using graphics, since the graphics object itself consume a big memory resource, especially if you work wit a lot graphics object. Besides, my articles will mostly use Paint event as well.

No comments: