System.Drawing.Graphics.FromHdc Method

Creates a new System.Drawing.Graphics from the specified handle to a device context and handle to a device.

Syntax

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)

Parameters

hdc
Handle to a device context.
hdevice
Handle to a device.

Returns

This method returns a new System.Drawing.Graphics for the specified device context and device.

Remarks

You should always call the Graphics.Dispose method to release the System.Drawing.Graphics and related resources created by the Graphics.FromHdc(IntPtr, IntPtr) method.

Even if the display device has an associated ICM color profile, ndptecgdiplus will not use that profile by default. To enable ICM for a System.Drawing.Graphics, construct the System.Drawing.Graphics from an HDC after you pass the HDC (and ICM_ON) to the SetICMMode function. Then any drawing done by the System.Drawing.Graphics will be adjusted according to the ICM profile associated with the display device. Enabling ICM will result in slower performance.

The state of the device context (mapping mode, logical unit, and the like) at the time you call Graphics.FromHdc(IntPtr, IntPtr) can affect rendering done by the System.Drawing.Graphics.

The device handle is typically used to query specific printer capabilities.

Requirements

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0