Using Device Contexts (DCs) in Visual Basic

Written by Mike D Sutton
EDais@mvps.org

Http://www.mvps.org/EDais/

- 01.05.2004 -

Introduction - What is a DC?

A Device Context (DC) is core of the GDI (Graphics Device Interface), Windows’ graphics library. Behind the scenes the DC is the interface between our applications and the output hardware, however when developing with them we rarely see this aspect and can just think of them as a holder for various drawing objects and properties. As its name suggests, a DC puts all the objects it contains in the context of a specific device which and will work out how to format those objects to be compatible and efficient with the desired device.

Note; in this last paragraph, ‘device’ means any kind of output device such as printer or monitor.

Before we start I just want to dispel a popular misconception; this being that a DCs and Bitmaps are synonymous when in fact they’re entirely different GDI objects. Although most API drawing routines take a Device Context as a target parameter, they actually manipulate the Bitmap selected into this DC rather than drawing ‘on’ the DC itself. Chapter 1 will go through the process in a little more depth.

Chapter index:

You can download this tutorial to disk for easier viewing offline as an Adobe Acrobat PDF:

Adobe Acrobat PDF doccument (127kb)

And the code for all the chapters:

Code (38.3kb)

Move on to chapter 1
Back to tutorials