THE OBJECTGRPICH

The Graphics Object
order to do any drawing with thenet framework, you need to obtain a graphics object. The Graphics class defines all the drawing functions that you can use to draw lines, ellipses, arcs, etc. These methods come in two forms Drawand Fillx. The Draw functions draw an outline of a shape, while the Fill functions will draw a solid shape]]]]].
AREA One thing to be aware of is the coordinate system. Point is actually in the upper left corner of your drawing area, larger values give points more to the right, and larger y values give points more to the bottom of the area. Another point to be aware of is that in the Betadocumentation, most of the drawing methods are listed as requiring the lower right point of the drawing nhowever the point that should be passed to them is the upper left one.
Graphics objects cannot be created directly with the new keyword, instead they must be created through a static method on the Graphics class itself. There are three methods that could be used, depending on your needs. Graphics.FromImage will create a graphics object from an Image. Likewise Graphics.Fromhdc and Graphics.FromHwnd will create graphics objects from a device context handle and a window handle respectively.
When drawing on a control or a form, the Graphics.FromHwnd method should be used. The window handle for the object that you want to draw on can be obtained through that object’s public Handle property. Once you are done using the Graphics object, you must make sure to dispose of it either through the C using construct or by calling its Dispose method. This will free up any resources allocated by the object.
Pens and Brushes
In order to use a Graphics object to draw, you will also need either a pen or a brush. Pens are used to draw outlines of shapes, while brushes are used to create filled in shapes. Both pens and brushes create GDI objects in Windows, so they need to be disposed of when you are done with them, in order to free these objects.
Pens are created by specifying a color and the width of the line the pen should create. You cannot create a brush directly, since it is an abstract class. Instead you must choose one of the following kinds of brushes.
HatchBrush fills with a hatch pattern specified by a member of the HatchStyle enumerationLinearGradientBrush fills by blending from a starting color at one side to an ending color on the otherPathGradientBrush fills from blending from a color at the center to a color on the outer edgeSolidBrush fills in a solid colorTextureBrush. fills with an image
Sample Code
All sample code given here was tested with Beta 2 of the .NET Framework. The code needs to reference System.Windows.Forms and System.Drawing to compile. In Visual Studio .NET you would add a these assemblies to your project’s references. If you choose to compile the sample code on the command line, you would use a command similar to this:csc smilecsr:System.Windows.Forms.dll r:System.Drawing.dll
The structure of the sample program is quite simple. The code consists of one class, Smile, which inherits from the System.Windows.Forms.Form class. The Main function of this class, simply instantiates one instance of Smile and starts it running.