winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Change modifier of `ToolStrip` button background rendering methods to `internal`

Open ArtemTatarinov opened this issue 4 years ago • 3 comments

If OnRenderButtonBackground, OnRenderDropDownButtonBackground, OnRenderSplitButtonBackground methods at ToolStripRenderer would be declared as not protected but internal, we could call them from derived classes.

Classes to affect: ToolStripRenderer, ToolStripProfessionalRenderer, ToolStripSystemRenderer, ToolStripHighContrastRenderer.

When trying to call the method from the derived class now: image

Inside the class 'A' itself we can call protected methods of the objects with the same type 'A' too, that's why we can call protected method OnRenderSplitButtonBackground from RendererOverride property.

ToolStripRenderer.cs: image

"Changing modifier on base class method from protected to internal may be the right approach here. "

Originally posted by @dreddy-work in https://github.com/dotnet/winforms/pull/5614#discussion_r700551190

ArtemTatarinov avatar Sep 02 '21 08:09 ArtemTatarinov

Unless the types are not public, changing protected to internal means we change public API, which is a breaking change. We can't do this.

RussKie avatar Sep 02 '21 22:09 RussKie

We have discussed this issue with @vladimir-krestov, maybe the best approach would be checking & converting RendererOverride to the ToolStripHighContrastRenderer type, like that (and the same for ToolStripButton and ToolStripDropDownButton):

image

What do you think about it, should we make this refactoring at the main branch?

ArtemTatarinov avatar Sep 08 '21 07:09 ArtemTatarinov

I am fine with later but i do not want to spend dedicated time on this. This should be a cleanup task that can be picked up if you are touching this file again for any other task.

dreddy-work avatar Sep 08 '21 21:09 dreddy-work

I'm not getting CS1540 anymore. Also only the base class, ToolStripRenderer is referencing RendererOverride, I don't see why that warning was applicable. Perhaps an analyzer bug?

Tanya-Solyanik avatar May 31 '23 19:05 Tanya-Solyanik