public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); Gdi32.R2 rasterOp = DeviceContext.BinaryRasterOperation; Gdi32.BKMODE bckMode = DeviceContext.BackgroundMode; if (rasterOp != Gdi32.R2.COPYPEN) { rasterOp = DeviceContext.SetRasterOperation(Gdi32.R2.COPYPEN); } if (bckMode != Gdi32.BKMODE.TRANSPARENT) { bckMode = DeviceContext.SetBackgroundMode(Gdi32.BKMODE.TRANSPARENT); } if (pen != null) { DeviceContext.SelectObject(pen.HPen, GdiObjectType.Pen); } Point oldPoint = new Point(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != Gdi32.BKMODE.TRANSPARENT) { DeviceContext.SetBackgroundMode(bckMode); } if (rasterOp != Gdi32.R2.COPYPEN) { DeviceContext.SetRasterOperation(rasterOp); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint); }
public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); DeviceContextBinaryRasterOperationFlags rasterOp = DeviceContext.BinaryRasterOperation; DeviceContextBackgroundMode bckMode = DeviceContext.BackgroundMode; if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { rasterOp = DeviceContext.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen); } if (bckMode != DeviceContextBackgroundMode.Transparent) { bckMode = DeviceContext.SetBackgroundMode(DeviceContextBackgroundMode.Transparent); } if (pen != null) { DeviceContext.SelectObject(pen.HPen, GdiObjectType.Pen); } Point oldPoint = new Point(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != DeviceContextBackgroundMode.Transparent) { DeviceContext.SetBackgroundMode(bckMode); } if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { DeviceContext.SetRasterOperation(rasterOp); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint); }