BlueMystical / Dark-Mode-Forms

Apply Dark Mode to all Controls in a Form [WinForms]
GNU General Public License v3.0
111 stars 15 forks source link

ComboBoxStyle changed by theme application #51

Closed Aniobodo closed 1 month ago

Aniobodo commented 1 month ago

There is a line of code that changed the assigned ComboBoxStyle to ComboBoxStyle.DropDownList.

if (control is ComboBox)
{
    Mode = IsDarkMode ? "DarkMode_CFD" : "ClearMode_CFD";               
    control.BeginInvoke(new Action(() => (control as ComboBox).SelectionLength = 0));
    if (control.Enabled == false && this.IsDarkMode)
    {
        **(control as ComboBox).DropDownStyle = ComboBoxStyle.DropDownList;**
    }
    SetWindowTheme(control.Handle, Mode, null);
}

Application of theme should not permanently change control style.

Aniobodo commented 1 month ago

If it is necessary to change the ComboBoxStyle to ComboBoxStyle.DropDownList before setting the theme, can you try to reset it back to the original style afterwards? .... The code below appears to work well on my side:

 if (control is ComboBox comboBox)
 {
     Mode = IsDarkMode ? "DarkMode_CFD" : "ClearMode_CFD";
     control.BeginInvoke(new Action(() => (control as ComboBox).SelectionLength = 0));

     Optional<ComboBoxStyle> originalStyle = default;//01.10.2024
     if (control.Enabled == false && this.IsDarkMode)
     {
         originalStyle = new(comboBox.DropDownStyle);//01.10.2024 Status change
         comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
     }
     SetWindowTheme(control.Handle, Mode, null);
     if (originalStyle.HasValue) comboBox.DropDownStyle = originalStyle.Value;//01.10.2024 reset original status
 }
BlueMystical commented 1 month ago

hi, thanks for the suggestions and for the Pull, its merged now. Regards.