private void PaintCustomBorder(IntPtr hWnd, IntPtr hRgn) { Color bColor; if (!Enabled && !BorderDisabledColor.IsEmpty) { bColor = BorderDisabledColor; } else if (Focused && !BorderFocusedColor.IsEmpty) { bColor = BorderFocusedColor; } else if (BorderColor != SystemColors.WindowFrame) { bColor = BorderColor; } else { //Regular border, which has already been drawn by the system at this point return; } using (var ncg = new NonClientGraphics(hWnd, hRgn)) { if (ncg.Graphics == null) { return; } ControlPaint.DrawBorder(ncg.Graphics, new Rectangle(new Point(0), Size), bColor, ButtonBorderStyle.Solid); } }
private void PaintCustomBorder(IntPtr hWnd, IntPtr hRgn) { var bColor = Color.Empty; //If a state color is empty, it means that the border color does not change with that state. if (!Enabled && !BorderDisabledColor.IsEmpty) { bColor = BorderDisabledColor; } else if (Focused && !BorderFocusedColor.IsEmpty) { bColor = BorderFocusedColor; } //Only draw the regular border if it is not the same color as the one already drawn by the system. else if (BorderColor != SystemColors.WindowFrame) { bColor = BorderColor; } if (!bColor.IsEmpty) { using (var ncg = new NonClientGraphics(hWnd, hRgn)) { var g = ncg.Graphics; if (g == null) { return; } ControlPaint.DrawBorder(g, NonClientRectangle, bColor, ButtonBorderStyle.Solid); } } }
private void PaintVisuallyStyledBorder(IntPtr hWnd, IntPtr hRgn) { var vsElement = VisualStyleElement.CreateElement(VSCLASS_LISTVIEW, 0, 0); if (VisualStyleRenderer.IsElementDefined(vsElement)) { using (var ncg = new NonClientGraphics(hWnd, hRgn)) { var g = ncg.Graphics; if (g == null) { return; } var vsRenderer = GetVisualStyleRenderer(vsElement); using (new GraphicsClippedToBorder(g, this, BorderStyle)) { vsRenderer.DrawBackground(g, NonClientRectangle); } } } }
private void PaintVisuallyStyledBorder(IntPtr hWnd, IntPtr hRgn) { var state = !Enabled ? 4 : Focused ? 3 : 1; var vsElement = VisualStyleElement.CreateElement(VSCLASS_EDIT, 6, state); if (VisualStyleRenderer.IsElementDefined(vsElement)) { var vsRenderer = GetVisualStyleRenderer(vsElement); using (var ncg = new NonClientGraphics(hWnd, hRgn)) { var g = ncg.Graphics; if (g == null) { return; } using (new GraphicsClippedToBorder(g, this, BorderStyle)) { vsRenderer.DrawBackground(g, new Rectangle(new Point(0), Size)); } } } }
private void PaintCustomBorder(IntPtr hWnd, IntPtr hRgn) { Color borderColor; if (!Enabled && !BorderDisabledColor.IsEmpty) { borderColor = BorderDisabledColor; } else if (Focused && !BorderFocusedColor.IsEmpty) { borderColor = BorderFocusedColor; } else { //Since this control does not support a single border out of the box, we draw the regular border //even if it's color is not different from the default. borderColor = BorderColor; } using (var ncg = new NonClientGraphics(hWnd, hRgn)) { var g = ncg.Graphics; if (g == null) { return; } var borderBounds = new Rectangle(new Point(0), Size); ControlPaint.DrawBorder(g, borderBounds, borderColor, ButtonBorderStyle.Solid); //As per the Microsoft documentation for this control, the Single BorderStyle is not supported //and the 3D border is always used. As a workaround, we paint the inner border with the same //color as the back color to simulate a thinner border. I have not tried it, but I believe that //a better solution would be to handle the WM_NCCALC message, but that would be more complicated... var borderSize = SystemInformation.BorderSize; borderBounds.Inflate(-borderSize.Width, -borderSize.Height); ControlPaint.DrawBorder(g, borderBounds, base.BackColor, ButtonBorderStyle.Solid); } }