Example #1
0
        public void DrawRectangle(WindowsPen pen, int x, int y, int width, int height)
        {
            Debug.Assert(pen != null, "pen == null");

            HandleRef hdc = new HandleRef(dc, dc.Hdc);

            if (pen != null)
            {
                dc.SelectObject(pen.HPen, GdiObjectType.Pen);
            }

            DeviceContextBinaryRasterOperationFlags rasterOp = dc.BinaryRasterOperation;

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                rasterOp = dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }

            Gdi32.SelectObject(hdc, Gdi32.GetStockObject(Gdi32.StockObject.HOLLOW_BRUSH));
            // Add 1 to widht and height to create the 'bounding box' (convert from point to size).
            IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width, y + height);

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                dc.SetRasterOperation(rasterOp);
            }
        }
Example #2
0
        /// <include file='doc\WindowsGraphics.uex' path='docs/doc[@for="WindowsGraphics.DrawRectangle3"]/*' />
        public void DrawRectangle(WindowsPen pen, int x, int y, int width, int height)
        {
            Debug.Assert(pen != null, "pen == null");

            HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc);

            if (pen != null)
            {
                this.dc.SelectObject(pen.HPen, GdiObjectType.Pen);
            }

            DeviceContextBinaryRasterOperationFlags rasterOp = this.dc.BinaryRasterOperation;

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                rasterOp = this.dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }

            IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(null, IntUnsafeNativeMethods.GetStockObject(IntNativeMethods.HOLLOW_BRUSH)));
            // Microsoft

            IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width, y + height);

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                this.dc.SetRasterOperation(rasterOp);
            }
        }
        public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2)
        {
            HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc);
            DeviceContextBinaryRasterOperationFlags binaryRasterOperation = this.dc.BinaryRasterOperation;
            DeviceContextBackgroundMode             backgroundMode        = this.dc.BackgroundMode;

            if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                binaryRasterOperation = this.dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }
            if (backgroundMode != DeviceContextBackgroundMode.Transparent)
            {
                backgroundMode = this.dc.SetBackgroundMode(DeviceContextBackgroundMode.Transparent);
            }
            if (pen != null)
            {
                this.dc.SelectObject(pen.HPen, GdiObjectType.Pen);
            }
            IntNativeMethods.POINT pt = new IntNativeMethods.POINT();
            IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, pt);
            IntUnsafeNativeMethods.LineTo(hdc, x2, y2);
            if (backgroundMode != DeviceContextBackgroundMode.Transparent)
            {
                this.dc.SetBackgroundMode(backgroundMode);
            }
            if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                this.dc.SetRasterOperation(binaryRasterOperation);
            }
            IntUnsafeNativeMethods.MoveToEx(hdc, pt.x, pt.y, null);
        }
        public void DrawRectangle(WindowsPen pen, int x, int y, int width, int height)
        {
            HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc);

            if (pen != null)
            {
                this.dc.SelectObject(pen.HPen, GdiObjectType.Pen);
            }
            DeviceContextBinaryRasterOperationFlags binaryRasterOperation = this.dc.BinaryRasterOperation;

            if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                binaryRasterOperation = this.dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }
            IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(null, IntUnsafeNativeMethods.GetStockObject(5)));
            IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width, y + height);
            if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                this.dc.SetRasterOperation(binaryRasterOperation);
            }
        }
Example #5
0
        public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2)
        {
            HandleRef hdc = new HandleRef(dc, dc.Hdc);

            DeviceContextBinaryRasterOperationFlags rasterOp = dc.BinaryRasterOperation;
            DeviceContextBackgroundMode             bckMode  = dc.BackgroundMode;

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                rasterOp = dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }

            if (bckMode != DeviceContextBackgroundMode.Transparent)
            {
                bckMode = dc.SetBackgroundMode(DeviceContextBackgroundMode.Transparent);
            }

            if (pen != null)
            {
                dc.SelectObject(pen.HPen, GdiObjectType.Pen);
            }

            Point oldPoint = new Point();

            IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint);
            IntUnsafeNativeMethods.LineTo(hdc, x2, y2);

            if (bckMode != DeviceContextBackgroundMode.Transparent)
            {
                dc.SetBackgroundMode(bckMode);
            }

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                dc.SetRasterOperation(rasterOp);
            }

            IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint);
        }
Example #6
0
 /// <devdoc>
 ///     Sets the DC ROP2 and returns the old value.
 /// </devdoc>
 public DeviceContextBinaryRasterOperationFlags SetRasterOperation(DeviceContextBinaryRasterOperationFlags rasterOperation)
 {
     return((DeviceContextBinaryRasterOperationFlags)IntUnsafeNativeMethods.SetROP2(new HandleRef(this, this.Hdc), (int)rasterOperation));
 }
 public DeviceContextBinaryRasterOperationFlags SetRasterOperation(DeviceContextBinaryRasterOperationFlags rasterOperation)
 {
     return (DeviceContextBinaryRasterOperationFlags) IntUnsafeNativeMethods.SetROP2(new HandleRef(this, this.Hdc), (int) rasterOperation);
 }