Skip to content

Transparent BackColor ignored when OnPaint is overridden in Button-derived controls #13496

Open
@Sekar47

Description

@Sekar47

.NET version

.NET Framework 4.8

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No

Issue description

When creating a custom control that inherits from System.Windows.Forms.Button and overrides the OnPaint method, setting the BackColor property to Color.Transparent does not render a transparent background. Instead, the control renders a black background, even when placed on a colored or image-filled parent.

When the overridden OnPaint is commented out, the transparent background works as expected.

Image
Image

WindowsFormsApp1.zip

Steps to reproduce

1.Open the provided sample solution
2.Open the form (Form2) in the Designer.
3.In the Properties window of CustomButton:

  • Set the BackColor property to Transparent.
  • Set the ForeColor property to any visible color (e.g., Blue).
    4.Save and run the application.
    5.The CustomButton renders with a black background, even though the BackColor was set to Transparent.
    6.If set the BackColor to a non-transparent color (Eg: Color.Red).
    7.The CustomButton now displays the correct red background as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions