Fix tool strip border in dark theme #8899
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #8864
Screenshots
Before
After
Proposed changes
At the moment there is a couple of cases where a custom
ToolStrip.Renderer
solves a task not related to dark theme.ToolStripEx
class)Current implementation of dark theme does not consider the cases above. It does
to all toolstrips, which breaks the cases 1. 2. above.
This PR does such that if a ToolStrip needs custom rendering, it uses on of 2 predefined renderers,
ToolStripExRenderer
orToolStripExThemeAwareRenderer
, both of which support scenarios 1. and 2. from above.Why not use 1 renderer per 1 solved problem?
Because
ToolStripRenderer
design makes it impossible.It offers 2 ways of customization:
RenderMenuItemBackground
OnRenderMenuItemBackground
The event mechanism fails because it cannot suppress default painting, except the few cases when ther is an
eventArgs.Handled
field.The inheritance mechanism does not allow you to compose different renderers so that each is responsible for solving 1 problem.
Amusingly,
ToolStripRenderer
does offer an ok way to compose renderers, which is a virtual propertyToolStripRenderer.RendererOverride
, but guess what, it's internal.Every time I stumble upon
virtual internal
pattern in a library code, I cannot help feel that library developer considers other developers, especially me, second class.Test environment(s)
✒️ I contribute this code under The Developer Certificate of Origin.