public static void DrawRect(Graphics graphics, int x0, int y0, int x1, int y1, Color colour) { IntPtr hdc = graphics.GetHdc(); try { IntPtr pen = CreatePen(PenStyle.PS_SOLID, 1, (uint)ColorTranslator.ToWin32(colour)); IntPtr oldpen = SelectObject(hdc, pen); try { MoveToEx(hdc, x0, y0, IntPtr.Zero); POINT[] points = new POINT[] { new Point(x0, y0), new POINT(x0, y0), new POINT(x1, y0), new POINT(x1, y1), new POINT(x0, y1), new POINT(x0, y0) }; PolylineTo(hdc, points, (uint)points.Length); } finally { DeleteObject(SelectObject(hdc, oldpen)); } } finally { graphics.ReleaseHdc(); } }
static extern bool PolylineTo(IntPtr hdc, POINT[] lppt, uint cCount);