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) { 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); } IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(null, IntUnsafeNativeMethods.GetStockObject(IntNativeMethods.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); } }
protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground, bool disabledColors) { Color control = checkBackground; Color contrastControlDark = borderColor; if (!this.Control.Enabled && disabledColors) { contrastControlDark = ControlPaint.ContrastControlDark; control = SystemColors.Control; } float dpiScaleRatio = CheckableControlBaseAdapter.GetDpiScaleRatio(e.Graphics); using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, contrastControlDark)) { using (WindowsBrush brush = new WindowsSolidBrush(graphics.DeviceContext, control)) { if (dpiScaleRatio > 1.1) { bounds.Width--; bounds.Height--; graphics.DrawAndFillEllipse(pen, brush, bounds); bounds.Inflate(-1, -1); } else { DrawAndFillEllipse(graphics, pen, brush, bounds); } } } } }
protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground, bool disabledColors) { Color field = checkBackground; Color border = borderColor; if (!Control.Enabled && disabledColors) { border = ControlPaint.ContrastControlDark; field = SystemColors.Control; } float scale = GetDpiScaleRatio(e.Graphics); using( WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics) ) { using( WindowsPen borderPen = new WindowsPen(wg.DeviceContext, border) ) { using( WindowsBrush fieldBrush = new WindowsSolidBrush(wg.DeviceContext, field) ) { // for Dev10 525537, in high DPI mode when we draw ellipse as three rectantles, // the quality of ellipse is poor. Draw it directly as ellipse if(scale > 1.1) { bounds.Width--; bounds.Height--; wg.DrawAndFillEllipse(borderPen, fieldBrush, bounds); bounds.Inflate(-1, -1); } else { DrawAndFillEllipse(wg, borderPen, fieldBrush, bounds); } } } } }
/// Drawing methods. public unsafe void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); if (pen != null) { // 1. Select the pen in the DC Gdi32.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } // 2. call the functions // we first draw a path that goes : // from center of pie, draw arc (this draw the line to the beginning of the arc // then, draw the closing line. // paint the path with the pen int sideLength = Math.Min(bounds.Width, bounds.Height); Point p = new Point(bounds.X + sideLength / 2, bounds.Y + sideLength / 2); int radius = sideLength / 2; IntUnsafeNativeMethods.BeginPath(hdc); Point oldPoint = default; IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, &oldPoint); IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
public void DrawRectangle(WindowsPen pen, int x, int y, int width, int height) { Debug.Assert(pen != null, "pen == null"); HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); if (pen != null) { DeviceContext.SelectObject(pen.HPen, GdiObjectType.Pen); } Gdi32.R2 rasterOp = DeviceContext.BinaryRasterOperation; if (rasterOp != Gdi32.R2.COPYPEN) { rasterOp = DeviceContext.SetRasterOperation(Gdi32.R2.COPYPEN); } Gdi32.SelectObject(hdc, Gdi32.GetStockObject(Gdi32.StockObject.HOLLOW_BRUSH)); // Add 1 to width and height to create the 'bounding box' (convert from point to size). IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width, y + height); if (rasterOp != Gdi32.R2.COPYPEN) { DeviceContext.SetRasterOperation(rasterOp); } }
private void DrawEllipse(WindowsPen pen, WindowsBrush brush, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); if (pen != null) { IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } if (brush != null) { IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(brush, brush.HBrush)); } IntUnsafeNativeMethods.Ellipse(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect); }
public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); if (pen != null) { IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } int num = Math.Min(bounds.Width, bounds.Height); Point point = new Point(bounds.X + (num / 2), bounds.Y + (num / 2)); int radius = num / 2; IntUnsafeNativeMethods.BeginPath(hdc); IntUnsafeNativeMethods.MoveToEx(hdc, point.X, point.Y, null); IntUnsafeNativeMethods.AngleArc(hdc, point.X, point.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, point.X, point.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds) { if (wg != null) { wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y), new Point(bounds.X + 8, bounds.Y)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X, bounds.Y + 4), new Point(bounds.X, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10)); } }
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); } }
protected void DrawCheckFlat(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ColorData colors) { Rectangle bounds = layout.checkBounds; // Removed subtracting one for Width and Height. In Everett we needed to do this, // since we were using GDI+ to draw the border. Now that we are using GDI, // we should not do before drawing the border. if (!layout.options.everettButtonCompat) { bounds.Width--; bounds.Height--; } using (WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) { using(WindowsPen pen = new WindowsPen(wg.DeviceContext, checkBorder)){ wg.DrawRectangle(pen, bounds); } // Now subtract, since the rest of the code is like Everett. if (layout.options.everettButtonCompat) { bounds.Width--; bounds.Height--; } bounds.Inflate(-1, -1); } if (Control.CheckState == CheckState.Indeterminate) { bounds.Width++; bounds.Height++; DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, bounds); } else { using( WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) { using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground)) { // Even though we are using GDI here as opposed to GDI+ in Everett, we still need to add 1. bounds.Width++; bounds.Height++; wg.FillRectangle(brush, bounds); } } } DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true); }
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(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); }
private void DrawEllipse(WindowsPen pen, WindowsBrush brush, int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect) { // y-coord of lower-right corner of rectangle HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); if (pen != null) { // 1. Select the pen in the DC Gdi32.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } if (brush != null) { Gdi32.SelectObject(hdc, new HandleRef(brush, brush.HBrush)); } // 2. call the function Gdi32.Ellipse(DeviceContext, nLeftRect, nTopRect, nRightRect, nBottomRect); }
private void DrawEllipse(WindowsPen pen, WindowsBrush brush, int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect) { // y-coord of lower-right corner of rectangle HandleRef hdc = new HandleRef(dc, dc.Hdc); if (pen != null) { // 1. Select the pen in the DC Interop.Gdi32.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } if (brush != null) { Interop.Gdi32.SelectObject(hdc, new HandleRef(brush, brush.HBrush)); } // 2. call the function IntUnsafeNativeMethods.Ellipse(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect); }
public void DrawAndFillEllipse(WindowsPen pen, WindowsBrush brush, Rectangle bounds) => DrawEllipse(pen, brush, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
// Helper method to overcome the poor GDI ellipse drawing routine // VSWhidbey #334097 private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds) { Debug.Assert(wg != null,"Calling DrawAndFillEllipse with null wg"); if (wg == null) { return; } wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 0), new Point(bounds.X + 8, bounds.Y + 0)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 0, bounds.Y + 4), new Point(bounds.X + 0, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10)); }
private void Draw3DBorderRaised(Graphics g, ref Rectangle bounds, ColorData colors) { bool flag = colors.buttonFace.ToKnownColor() == SystemColors.Control.ToKnownColor(); using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(g)) { WindowsPen pen; Point point = new Point((bounds.X + bounds.Width) - 1, bounds.Y); Point point2 = new Point(bounds.X, bounds.Y); Point point3 = new Point(bounds.X, (bounds.Y + bounds.Height) - 1); Point point4 = new Point((bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1); using (pen = flag ? new WindowsPen(graphics.DeviceContext, SystemColors.ControlLightLight) : new WindowsPen(graphics.DeviceContext, colors.highlight)) { graphics.DrawLine(pen, point, point2); graphics.DrawLine(pen, point2, point3); } if (flag) { pen = new WindowsPen(graphics.DeviceContext, SystemColors.ControlDarkDark); } else { pen = new WindowsPen(graphics.DeviceContext, colors.buttonShadowDark); } try { point.Offset(0, -1); graphics.DrawLine(pen, point3, point4); graphics.DrawLine(pen, point4, point); } finally { pen.Dispose(); } point.Offset(-1, 2); point2.Offset(1, 1); point3.Offset(1, -1); point4.Offset(-1, -1); if (flag) { if (SystemInformation.HighContrast) { pen = new WindowsPen(graphics.DeviceContext, SystemColors.ControlLight); } else { pen = new WindowsPen(graphics.DeviceContext, SystemColors.Control); } } else { pen = new WindowsPen(graphics.DeviceContext, colors.buttonFace); } try { graphics.DrawLine(pen, point, point2); graphics.DrawLine(pen, point2, point3); } finally { pen.Dispose(); } if (flag) { pen = new WindowsPen(graphics.DeviceContext, SystemColors.ControlDark); } else { pen = new WindowsPen(graphics.DeviceContext, colors.buttonShadow); } try { point.Offset(0, -1); graphics.DrawLine(pen, point3, point4); graphics.DrawLine(pen, point4, point); } finally { pen.Dispose(); } } }
internal static void DrawFlatFocus(Graphics g, Rectangle r, Color c) { using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(g)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, c)) { graphics.DrawRectangle(pen, r); } } }
protected void DrawCheckFlat(PaintEventArgs e, ButtonBaseAdapter.LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ButtonBaseAdapter.ColorData colors) { Rectangle checkBounds = layout.checkBounds; if (!layout.options.everettButtonCompat) { checkBounds.Width--; checkBounds.Height--; } using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, checkBorder)) { graphics.DrawRectangle(pen, checkBounds); } if (layout.options.everettButtonCompat) { checkBounds.Width--; checkBounds.Height--; } checkBounds.Inflate(-1, -1); } if (this.Control.CheckState == CheckState.Indeterminate) { checkBounds.Width++; checkBounds.Height++; ButtonBaseAdapter.DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, checkBounds); } else { using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsBrush brush = new WindowsSolidBrush(graphics2.DeviceContext, checkBackground)) { checkBounds.Width++; checkBounds.Height++; graphics2.FillRectangle(brush, checkBounds); } } } this.DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true); }
internal WindowsPen GetCachedWindowsPen(Color color) { WindowsPen pen = (WindowsPen)this.pens[color]; if (pen == null) { pen = new WindowsPen(color); this.pens.Add(color, pen); } return pen; }
private void Draw3DBorderRaised(Graphics g, ref Rectangle bounds, ColorData colors) { bool stockColor = colors.buttonFace.ToKnownColor() == SystemColors.Control.ToKnownColor(); using( WindowsGraphics wg = WindowsGraphics.FromGraphics(g) ) { // Draw counter-clock-wise. Point p1 = new Point(bounds.X + bounds.Width - 1, bounds.Y ); // upper inner right. Point p2 = new Point(bounds.X , bounds.Y ); // upper left. Point p3 = new Point(bounds.X , bounds.Y + bounds.Height - 1 ); // bottom inner left. Point p4 = new Point(bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1 ); // inner bottom right. // Draw counter-clock-wise. // top + left WindowsPen pen = stockColor ? new WindowsPen(wg.DeviceContext, SystemColors.ControlLightLight) : new WindowsPen(wg.DeviceContext, colors.highlight); try { wg.DrawLine(pen, p1, p2); // top (right-left) wg.DrawLine(pen, p2, p3); // left(up-down) } finally { pen.Dispose(); } // bottom + right if (stockColor) { pen = new WindowsPen(wg.DeviceContext, SystemColors.ControlDarkDark); } else { pen = new WindowsPen(wg.DeviceContext, colors.buttonShadowDark); } try { p1.Offset(0,-1); // need to paint last pixel too. wg.DrawLine(pen, p3, p4); // bottom(left-right) wg.DrawLine(pen, p4, p1); // right (bottom-up) } finally { pen.Dispose(); } // Draw inset p1.Offset(-1, 2); p2.Offset( 1, 1); p3.Offset( 1,-1); p4.Offset(-1,-1); if (stockColor) { if (SystemInformation.HighContrast) { pen = new WindowsPen(wg.DeviceContext, SystemColors.ControlLight); } else { pen = new WindowsPen(wg.DeviceContext, SystemColors.Control); } } else { pen = new WindowsPen(wg.DeviceContext, colors.buttonFace); } // top + left inset try { wg.DrawLine(pen, p1, p2); // top (right-left) wg.DrawLine(pen, p2, p3); // left(up-down) } finally { pen.Dispose(); } // Bottom + right inset if (stockColor) { pen = new WindowsPen(wg.DeviceContext, SystemColors.ControlDark); } else { pen = new WindowsPen(wg.DeviceContext, colors.buttonShadow); } try { p1.Offset(0,-1); // need to paint last pixel too. wg.DrawLine(pen, p3, p4); // bottom(left-right) wg.DrawLine(pen, p4, p1); // right (bottom-up) } finally { pen.Dispose(); } } }
internal static void DrawFlatFocus(Graphics g, Rectangle r, Color c) { using(WindowsGraphics wg = WindowsGraphics.FromGraphics(g)) { using (WindowsPen focus = new WindowsPen(wg.DeviceContext, c)) { wg.DrawRectangle(focus, r); } } }
internal void GetContrastedWindowsPens(Color baseline, ref WindowsPen darkPen, ref WindowsPen lightPen) { Debug.Assert(this.DataGridView != null); int darkDistance = ColorDistance(baseline, SystemColors.ControlDark); int lightDistance = ColorDistance(baseline, SystemColors.ControlLightLight); if (SystemInformation.HighContrast) { if (darkDistance < DATAGRIDVIEWCELL_highConstrastThreshold) { darkPen = this.DataGridView.GetCachedWindowsPen(ControlPaint.DarkDark(baseline)); } else { darkPen = this.DataGridView.GetCachedWindowsPen(SystemColors.ControlDark); } if (lightDistance < DATAGRIDVIEWCELL_highConstrastThreshold) { lightPen = this.DataGridView.GetCachedWindowsPen(ControlPaint.LightLight(baseline)); } else { lightPen = this.DataGridView.GetCachedWindowsPen(SystemColors.ControlLightLight); } } else { if (darkDistance < DATAGRIDVIEWCELL_constrastThreshold) { darkPen = this.DataGridView.GetCachedWindowsPen(ControlPaint.Dark(baseline)); } else { darkPen = this.DataGridView.GetCachedWindowsPen(SystemColors.ControlDark); } if (lightDistance < DATAGRIDVIEWCELL_constrastThreshold) { lightPen = this.DataGridView.GetCachedWindowsPen(ControlPaint.Light(baseline)); } else { lightPen = this.DataGridView.GetCachedWindowsPen(SystemColors.ControlLightLight); } } }
public void DrawLine(WindowsPen pen, Point p1, Point p2) { this.DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y); }
// DrawRectangle overloads public void DrawRectangle(WindowsPen pen, Rectangle rect) { DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); }
internal static Rectangle DrawPopupBorder(Graphics g, Rectangle r, ButtonBaseAdapter.ColorData colors) { using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(g)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, colors.highlight)) { using (WindowsPen pen2 = new WindowsPen(graphics.DeviceContext, colors.buttonShadow)) { using (WindowsPen pen3 = new WindowsPen(graphics.DeviceContext, colors.buttonFace)) { graphics.DrawLine(pen, r.Right - 1, r.Top, r.Right - 1, r.Bottom); graphics.DrawLine(pen, r.Left, r.Bottom - 1, r.Right, r.Bottom - 1); graphics.DrawLine(pen2, r.Left, r.Top, r.Left, r.Bottom); graphics.DrawLine(pen2, r.Left, r.Top, r.Right - 1, r.Top); graphics.DrawLine(pen3, r.Right - 2, r.Top + 1, r.Right - 2, r.Bottom - 1); graphics.DrawLine(pen3, r.Left + 1, r.Bottom - 2, r.Right - 1, r.Bottom - 2); } } } } r.Inflate(-1, -1); return r; }
public void DrawRectangle(WindowsPen pen, Rectangle rect) { this.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); }
// DrawLine overloads /// <summary> /// Draws a line starting from p1 (included) to p2 (excluded). LineTo doesn't paint the last /// pixel because if it did the intersection points of connected lines would be drawn multiple /// times turning them back to the background color. /// </summary> public void DrawLine(WindowsPen pen, Point p1, Point p2) => DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y);
public void DrawAndFillEllipse(WindowsPen pen, WindowsBrush brush, Rectangle bounds) { this.DrawEllipse(pen, brush, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); }
internal static Rectangle DrawPopupBorder(Graphics g, Rectangle r, ColorData colors) { using (WindowsGraphics wg = WindowsGraphics.FromGraphics( g )) { using( WindowsPen high = new WindowsPen(wg.DeviceContext, colors.highlight), shadow = new WindowsPen(wg.DeviceContext, colors.buttonShadow), face = new WindowsPen(wg.DeviceContext, colors.buttonFace)) { wg.DrawLine(high, r.Right-1 , r.Top, r.Right-1, r.Bottom); wg.DrawLine(high, r.Left, r.Bottom-1, r.Right, r.Bottom-1); wg.DrawLine(shadow, r.Left, r.Top, r.Left , r.Bottom); wg.DrawLine(shadow, r.Left, r.Top, r.Right- 1, r.Top); wg.DrawLine(face, r.Right - 2, r.Top + 1, r.Right - 2, r.Bottom - 1); wg.DrawLine(face, r.Left + 1, r.Bottom - 2, r.Right - 1, r.Bottom - 2); } } r.Inflate(-1, -1); return r; }