[DllImport("user32.dll")] static extern IntPtr MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint); [DllImport("gdi32.dll")] static extern bool LineTo(IntPtr hdc, int x, int y); // ... IntPtr hdc = graphicsObject.GetHdc(); MoveToEx(hdc, 0, 0, IntPtr.Zero); LineTo(hdc, 50, 50); graphicsObject.ReleaseHdc(hdc);
public static class NativeMethods { [DllImport("gdiplus.dll")] public static extern int GdipDrawImageRectI(IntPtr graphics, IntPtr image, int x, int y, int width, int height); } // ... IntPtr hdc = graphicsObject.GetHdc(); NativeMethods.GdipDrawImageRectI(hdc, bitmapObject.GetHbitmap(), 0, 0, bitmapObject.Width, bitmapObject.Height); graphicsObject.ReleaseHdc(hdc);In this example, we use the GetHdc method to obtain a handle to the device context, which we then pass to a native GDI+ function, `GdipDrawImageRectI`, to draw an image onto the screen. The package library for this method and related classes and functions is `System.Drawing.dll`.