Skip to content

Commit

Permalink
Fix ToolStripButtons in PropertyGrid should have obvious distinct bet…
Browse files Browse the repository at this point in the history
…ween focused and checked status #4268

Added a special method for high contrast mode that draws a black and white dashed border
  • Loading branch information
SergeySmirnov-Akvelon committed Nov 25, 2020
1 parent 12b8059 commit 6ffd171
Showing 1 changed file with 47 additions and 9 deletions.
Expand Up @@ -27,18 +27,56 @@ protected override void OnPaint(PaintEventArgs e)
// which calls the "VisualStyleRenderer.DrawBackground" method for drawing
// For high contrast mode we use the "ToolStripHighContrastRenderer.OnRenderButtonBackground" method
// which calls the "Graphics.DrawRectangle" method for drawing
if (!SystemInformation.HighContrast)
if (SystemInformation.HighContrast)
{
bounds.Height -= 1;
DrawHightContrastDashedBorer(e.Graphics);
}
else
{
DrawDashedBorer(e.Graphics);
}

// We support only one type of settings for all borders since it is consistent with the behavior of the same controls
ControlPaint.DrawBorder(e.Graphics, bounds,
leftColor: Color.Black, leftWidth: 1, leftStyle: ButtonBorderStyle.Dashed, // left
topColor: Color.Black, topWidth: 1, topStyle: ButtonBorderStyle.Dashed, // top
rightColor: Color.Black, rightWidth: 1, rightStyle: ButtonBorderStyle.Dashed, // right
bottomColor: Color.Black, bottomWidth: 1, bottomStyle: ButtonBorderStyle.Dashed); // bottom;
}
}

private void DrawDashedBorer(Graphics graphics)
{
var bounds = ClientBounds;

// It is necessary so that when HighContrast is off, the size of the dotted borders
// coincides with the size of the button background
// For normal mode we use the "ToolStripSystemRenderer.RenderItemInternal" method
// which calls the "VisualStyleRenderer.DrawBackground" method for drawing
// For high contrast mode we use the "ToolStripHighContrastRenderer.OnRenderButtonBackground" method
// which calls the "Graphics.DrawRectangle" method for drawing
bounds.Height -= 1;

// We support only one type of settings for all borders since it is consistent with the behavior of the same controls
ControlPaint.DrawBorder(graphics, bounds,
leftColor: Color.Black, leftWidth: 1, leftStyle: ButtonBorderStyle.Dashed, // left
topColor: Color.Black, topWidth: 1, topStyle: ButtonBorderStyle.Dashed, // top
rightColor: Color.Black, rightWidth: 1, rightStyle: ButtonBorderStyle.Dashed, // right
bottomColor: Color.Black, bottomWidth: 1, bottomStyle: ButtonBorderStyle.Dashed); // bottom;*/
}

private void DrawHightContrastDashedBorer(Graphics graphics)
{
var bounds = ClientBounds;
float[] dashValues = { 2, 2 };
int penWidth = 2;

var focusPen1 = new Pen(SystemColors.ControlText, penWidth)
{
DashPattern = dashValues
};

var focusPen2 = new Pen(SystemColors.Control, penWidth)
{
DashPattern = dashValues,
DashOffset = 2
};

graphics.DrawRectangle(focusPen1, bounds);
graphics.DrawRectangle(focusPen2, bounds);
}
}
}

0 comments on commit 6ffd171

Please sign in to comment.