The Graphics Object

The root of all GDI+ graphics capabilities for .NET is the Graphics object. This is analogous to the Win32 DC and can be obtained explicitly from a window handle or is passed to your application from, say, the OnPaint event. To obtain a Graphics object in Managed C++, for example, you would write the following code:

HDC dc;
PAINTSTRUCT ps;
Graphics *pGraphics;

Dc=BeginPaint(hWnd,&ps)
pGraphics=new Graphics(dc);
// use the Graphics...
EndPaint(hWnd,&ps);

For the purposes of this chapter, we'll assume that GDI+ operations will take place in the context of a Windows Forms application and that the Graphics object is handed to you in an event delegate. For example, we see the Graphics object that's supplied in the PaintEventArgs ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.