public void DrawXORRectangle( Graphics grp,
int X1, int Y1, int X2, int Y2 )
{
// Extract the Win32 HDC from the Graphics object supplied.
IntPtr hdc = grp.GetHdc();
// Create a pen with a dotted style to draw the border of the
// rectangle.
IntPtr gdiPen = CreatePen( penStyle,
1, BLACK_PEN );
// Set the ROP cdrawint mode to XOR.
SetROP2( hdc, R2_XORPEN );
// Select the pen into the device context.
IntPtr oldPen = SelectObject( hdc, gdiPen );
// Create a stock NULL_BRUSH brush and select it into the device
// context so that the rectangle isn't filled.
IntPtr oldBrush = SelectObject( hdc,
GetStockObject( NULL_BRUSH ) );
// Now XOR the hollow rectangle on the Graphics object with
// a dotted outline.
Rectangle( hdc, X1, Y1, X2, Y2 );
// Put the old stuff back where it was.
SelectObject( hdc, oldBrush ); // no need to delete a stock object
SelectObject( hdc, oldPen );
DeleteObject( gdiPen ); // but we do need to delete the pen
// Return the device context to Windows.
grp.ReleaseHdc( hdc );
}