dotnet / dotnet/winforms

Can't Remove DarkMode Form Theme inside OnHandleCreated event

Open
#13,460 5 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-DarkMode
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

.NET 10.0.100-preview.5.25257.112

### Did it work in .NET Framework?

No

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

No, also repro in .NET 9.0 which it started to be supported.

### Issue description

The Compatible Method to Create Custom Painting On NoneClient Area of Form is To Remove Form Theme inside OnHandleCreated event this option is Not Supported when using DarkMode

### Steps to reproduce

1- Create a winforms .NET Core project .
2- Enable DarkMode by Application.SetColorMode(SystemColorMode.Dark) in Program.cs file.
3- override void OnHandleCreated event to remove The Theme

```
protected override void OnHandleCreated(EventArgs e)
{
PInvoke.SetWindowTheme(Handle,"","");
}
```

https://github.com/user-attachments/assets/93fd714b-9c65-4be2-91ea-a32a38fc0965

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.