public void FillRectangle(WindowsBrush brush, int x, int y, int width, int height) { Debug.Assert(brush != null, "brush == null"); HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); IntPtr hBrush = brush.HBrush; // We don't delete this handle since we didn't create it. IntNativeMethods.RECT rect = new IntNativeMethods.RECT(x, y, x + width, y + height); #if WINFORMS_PUBLIC_GRAPHICS_LIBRARY if (brush is WindowsHatchBrush) { int clr = ColorTranslator.ToWin32(((WindowsHatchBrush)brush).BackGroundColor); IntUnsafeNativeMethods.SetBkColor(hdc, clr); IntUnsafeNativeMethods.SetBkMode(hdc, (int)DeviceContextBackgroundMode.Transparent); } #endif IntUnsafeNativeMethods.FillRect(hdc, ref rect, new HandleRef(brush, hBrush)); }