Open JeremyKuhne opened 3 years ago
namespace System.Windows.Forms
{
public partial class ControlPaint
{
public static void DrawBorder(IDeviceContext deviceContext, Rectangle bounds, Color color, ButtonBorderStyle style);
public static void DrawBorder(IDeviceContext deviceContext, Rectangle bounds, Color leftColor, int leftWidth, ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle, Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor, int bottomWidth, ButtonBorderStyle bottomStyle);
public static void DrawBorder3D(IDeviceContext deviceContext, int x, int y, int width, int height);
public static void DrawBorder3D(IDeviceContext deviceContext, int x, int y, int width, int height, Border3DStyle style);
public static void DrawBorder3D(IDeviceContext deviceContext, int x, int y, int width, int height, Border3DStyle style, Border3DSide sides);
public static void DrawBorder3D(IDeviceContext deviceContext, Rectangle rectangle);
public static void DrawBorder3D(IDeviceContext deviceContext, Rectangle rectangle, Border3DStyle style);
public static void DrawBorder3D(IDeviceContext deviceContext, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
public static void DrawButton(IDeviceContext deviceContext, int x, int y, int width, int height, ButtonState state);
public static void DrawButton(IDeviceContext deviceContext, Rectangle rectangle, ButtonState state);
public static void DrawCaptionButton(IDeviceContext deviceContext, int x, int y, int width, int height, CaptionButton button, ButtonState state);
public static void DrawCaptionButton(IDeviceContext deviceContext, Rectangle rectangle, CaptionButton button, ButtonState state);
public static void DrawCheckBox(IDeviceContext deviceContext, int x, int y, int width, int height, ButtonState state);
public static void DrawCheckBox(IDeviceContext deviceContext, Rectangle rectangle, ButtonState state);
public static void DrawComboButton(IDeviceContext deviceContext, int x, int y, int width, int height, ButtonState state);
public static void DrawComboButton(IDeviceContext deviceContext, Rectangle rectangle, ButtonState state);
public static void DrawContainerGrabHandle(IDeviceContext deviceContext, Rectangle bounds);
public static void DrawFocusRectangle(IDeviceContext deviceContext, Rectangle rectangle);
public static void DrawFocusRectangle(IDeviceContext deviceContext, Rectangle rectangle, Color foreColor, Color backColor);
public static void DrawGrabHandle(IDeviceContext deviceContext, Rectangle rectangle, bool primary, bool enabled);
public static void DrawGrid(IDeviceContext deviceContext, Rectangle area, Size pixelsBetweenDots, Color backColor);
public static void DrawLockedFrame(IDeviceContext deviceContext, Rectangle rectangle, bool primary);
public static void DrawMenuGlyph(IDeviceContext deviceContext, int x, int y, int width, int height, MenuGlyph glyph);
public static void DrawMenuGlyph(IDeviceContext deviceContext, int x, int y, int width, int height, MenuGlyph glyph, Color foreColor, Color backColor);
public static void DrawMenuGlyph(IDeviceContext deviceContext, Rectangle rectangle, MenuGlyph glyph);
public static void DrawMenuGlyph(IDeviceContext deviceContext, Rectangle rectangle, MenuGlyph glyph, Color foreColor, Color backColor);
public static void DrawMixedCheckBox(IDeviceContext deviceContext, int x, int y, int width, int height, ButtonState state);
public static void DrawMixedCheckBox(IDeviceContext deviceContext, Rectangle rectangle, ButtonState state);
public static void DrawRadioButton(IDeviceContext deviceContext, int x, int y, int width, int height, ButtonState state);
public static void DrawRadioButton(IDeviceContext deviceContext, Rectangle rectangle, ButtonState state);
public static void DrawScrollButton(IDeviceContext deviceContext, int x, int y, int width, int height, ScrollButton button, ButtonState state);
public static void DrawScrollButton(IDeviceContext deviceContext, Rectangle rectangle, ScrollButton button, ButtonState state);
public static void DrawSelectionFrame(IDeviceContext deviceContext, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor);
public static void DrawSizeGrip(IDeviceContext deviceContext, Color backColor, int x, int y, int width, int height);
public static void DrawSizeGrip(IDeviceContext deviceContext, Color backColor, Rectangle bounds);
public static void DrawVisualStyleBorder(IDeviceContext deviceContext, Rectangle bounds);
// Omitted, IDeviceContext doesn't make sense as this also takes Image
// public static void DrawImageDisabled(Graphics graphics, Image image, int x, int y, Color background);
// Already exists
// public static void DrawStringDisabled(IDeviceContext deviceContext, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format);
}
}
@JeremyKuhne I imagine when implementing this we will need tests added to ControlPaintTests
? How do we get a IDeviceContext
similar to using Graphics graphics = Graphics.FromImage(image);
?
How do we get a IDeviceContext similar to using Graphics graphics = Graphics.FromImage(image);?
Graphics
actually implements it, so you can just use it. :)
Awesome, so we aren't changing the existing function signatures. We are adding new overloads?
I should be able to slowly put in some PRs and copy the existing tests.
Summary
Painting using
System.Drawing
(GDI+) has significant performance overhead over utilizing GDI. Internally WinForms has moved much of it's rendering to GDI (starting in .NET 2.0) and has provided some entry points with GDI viaIDeviceContext
. Adding overloads toControlPaint
methods will allow more performant rendering of custom controls. It allows direct use of paint event arguments inOnPaint
as they now exposeIDeviceContext
(as opposed toe.Graphics
, which has huge overhead).API
Details
Color
alpha will be ignored, as that requires GDI+ (we could throw, but that wouldn't fit with other APIs we currently have)IDeviceContext
is aGraphics
objectGraphics
offset and clipping ifIDeviceContext
is aGraphics
object