/// Drawing methods. /// <devdoc> /// </devdoc> public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef( this.dc, this.dc.Hdc); if( pen != null ) { // 1. Select the pen in the DC IntUnsafeNativeMethods.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); IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, null); IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
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); } } } } }
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))); // 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) { this.dc.SetRasterOperation(rasterOp); } }
/// Drawing methods. /// <devdoc> /// </devdoc> public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); if (pen != null) { // 1. Select the pen in the DC IntUnsafeNativeMethods.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); IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, null); IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
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); } } } } }
// 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)); }
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); }
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); }
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); }
protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground) { Color field = checkBackground; Color border = borderColor; if (!Control.Enabled) { // if we are not in HighContrast mode OR we opted into the legacy behavior if (!SystemInformation.HighContrast) { border = ControlPaint.ContrastControlDark; } // otherwise we are in HighContrast mode field = SystemColors.Control; } double 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)) { // 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); } } } } }
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)); } }
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(this.dc, this.dc.Hdc); if (pen != null) { // 1. Select the pen in the DC IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } if (brush != null) { IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(brush, brush.HBrush)); } // 2. call the function IntUnsafeNativeMethods.Ellipse(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect); }
public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); DeviceContextBinaryRasterOperationFlags rasterOp = this.dc.BinaryRasterOperation; DeviceContextBackgroundMode bckMode = this.dc.BackgroundMode; if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { rasterOp = this.dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen); } if (bckMode != DeviceContextBackgroundMode.Transparent) { bckMode = this.dc.SetBackgroundMode(DeviceContextBackgroundMode.Transparent); } if (pen != null) { this.dc.SelectObject(pen.HPen, GdiObjectType.Pen); } IntNativeMethods.POINT oldPoint = new IntNativeMethods.POINT(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != DeviceContextBackgroundMode.Transparent) { this.dc.SetBackgroundMode(bckMode); } if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { this.dc.SetRasterOperation(rasterOp); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.x, oldPoint.y, null); }
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); }
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( this.dc, this.dc.Hdc); if (pen != null) { // 1. Select the pen in the DC IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } if (brush != null) { IntUnsafeNativeMethods.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); }
// DrawRectangle overloads /// <include file='doc\WindowsGraphics.uex' path='docs/doc[@for="WindowsGraphics.DrawRectangle"]/*' /> public void DrawRectangle(WindowsPen pen, Rectangle rect) { DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); }
// DrawLine overloads /// <devdoc> /// 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. /// </devdoc> public void DrawLine(WindowsPen pen, Point p1, Point p2) { DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y); }
/// <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))); // [....] IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width , y + height ); if( rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen ) { this.dc.SetRasterOperation(rasterOp); } }
// DrawRectangle overloads public void DrawRectangle(WindowsPen pen, Rectangle rect) { DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); }
// DrawLine overloads /// <include file='doc\WindowsGraphics.uex' path='docs/doc[@for="WindowsGraphics.DrawLine"]/*' /> /// <devdoc> /// 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. /// </devdoc> public void DrawLine(WindowsPen pen, Point p1, Point p2) { DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y); }
/// <include file='doc\WindowsGraphics.uex' path='docs/doc[@for="WindowsGraphics.DrawLine3"]/*' /> public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); DeviceContextBinaryRasterOperationFlags rasterOp = this.dc.BinaryRasterOperation; DeviceContextBackgroundMode bckMode = this.dc.BackgroundMode; if( rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen ) { rasterOp = this.dc.SetRasterOperation( DeviceContextBinaryRasterOperationFlags.CopyPen ); } if( bckMode != DeviceContextBackgroundMode.Transparent ) { bckMode = this.dc.SetBackgroundMode( DeviceContextBackgroundMode.Transparent ); } if (pen != null) { this.dc.SelectObject(pen.HPen, GdiObjectType.Pen); } IntNativeMethods.POINT oldPoint = new IntNativeMethods.POINT(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if( bckMode != DeviceContextBackgroundMode.Transparent ) { this.dc.SetBackgroundMode( bckMode ); } if( rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen ) { this.dc.SetRasterOperation( rasterOp ); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.x, oldPoint.y, null); }