예제 #1
0
        public static void DrawRectangle(Graphics dc, PenStyles penStyle, int penWidth, Color col,
                                         int X1, int Y1, int X2, int Y2)
        {
            // Extract the Win32 HDC from the Graphics object supplied.
            IntPtr hdc = dc.GetHdc();

            // Create a pen.
            IntPtr gdiPen = GDI.CreatePen(penStyle, penWidth, GDI.RGB(col.R, col.G, col.B));

            GDI.SetROP2(hdc, drawingMode.R2_XORPEN);
            GDI.SetBkMode(hdc, TRANSPARENT);

            // Set the ROP cdrawint mode to XOR.
            GDI.SetROP2(hdc, drawingMode.R2_XORPEN);

            // Select the pen into the device context.
            IntPtr oldPen = GDI.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 = GDI.SelectObject(hdc, GDI.GetStockObject(NULL_BRUSH));

            // Now XOR the hollow rectangle on the Graphics object with
            // a dotted outline.
            GDI.Rectangle(hdc, X1, Y1, X2, Y2);

            // Put the old stuff back where it was.
            GDI.SelectObject(hdc, oldBrush);             // no need to delete a stock object
            GDI.SelectObject(hdc, oldPen);
            GDI.DeleteObject(gdiPen);                    // but we do need to delete the pen

            // Return the device context to Windows.
            dc.ReleaseHdc(hdc);
        }
예제 #2
0
        public static void DrawLine(PenStyles penStyle, int penWidth, Color col,
                                    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.
            IntPtr gdiPen = GDI.CreatePen(penStyle, penWidth, GDI.RGB(col.R, col.G, col.B));

            GDI.SetROP2(hdc, drawingMode.R2_XORPEN);
            GDI.SetBkMode(hdc, TRANSPARENT);

            // Set the ROP cdrawint mode to XOR.
            GDI.SetROP2(hdc, drawingMode.R2_XORPEN);

            // Select the pen into the device context.
            IntPtr oldPen = GDI.SelectObject(hdc, gdiPen);

            // Draw the line.
            GDI.MoveToEx(hdc, X1, Y1, 0);
            GDI.LineTo(hdc, X2, Y2);

            // Put the old stuff back where it was.
            GDI.SelectObject(hdc, oldPen);
            GDI.DeleteObject(gdiPen);

            // Return the device context to Windows.
            grp.ReleaseHdc(hdc);
        }