Combobox height does not get scaled correctly when dynamically added to a panel
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### .NET version
8.0
### Did it work in .NET Framework?
Not tested/verified
### Did it work in any of the earlier releases of .NET Core or .NET 5+?
_No response_
### Issue description
The height of a combobox control is not scaled correctly when it is dynamically added to a panel after it previously already received a `DpiChanged`-Event and `Application.SetHighDpiMode(HighDpiMode.PerMonitorV2)` is used.

If I manually call `RescaleConstantsForDpi(96, DeviceDpi);` after adding the control to the panel, it does get scaled correctly but I am not sure whether this is a stable workaround.
```cmd
Before RescaleConstantsForDpi: {Width=171, Height=24}
After RescaleConstantsForDpi: {Width=171, Height=33}
```

### Steps to reproduce
Form with a button and a panel. When the button is pressed add the combobox to the panel controls.

```csharp
public partial class MinimalRepro : Form
{
private ComboBox combobox;
public MinimalRepro()
{
InitializeComponent();
combobox = new ComboBox();
combobox.Items.AddRange(new object[] {
"Test 1",
"Test 2"
});
combobox.Text = "Test2";
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Controls.Clear();
panel1.Controls.Add(combobox);
// This hack fixes it!
// RescaleConstantsForDpi(96, DeviceDpi);
}
}
```
1. Show the form on the primary monitor (96 DPI)

2. Click the button

3. Move the form to the secondary monitor (144 DPI) => OK!

4. Click the button one or more times => The Combobox height is changed on the first click and wont be correct afterwards. 💥

Contributor guide
Assessment
This issue has not been assessed yet.