HeaderPane
Main
Hide
Share Link
Print

Switching While Forms Are Open

The SftStyle component switches the forms of the application while they are open, without closing or recreating them. A switch happens when the application sets SftStyle.DarkMode or SftStyle.HighContrastMode, and with Auto when the user changes the Windows light/dark setting or turns a contrast theme on or off. The SftStyle.DarkModeChanged and SftStyle.HighContrastChanged events report each switch.

An application can offer its own choice, for example a menu with Light, Dark and "Use Windows setting":

C#

private void menuLight_Click(object sender, EventArgs e) {
    sftStyle1.DarkMode = DarkModeEnum.Off;
}
private void menuDark_Click(object sender, EventArgs e) {
    sftStyle1.DarkMode = DarkModeEnum.On;
}
private void menuWindows_Click(object sender, EventArgs e) {
    sftStyle1.DarkMode = DarkModeEnum.Auto;
}

VB

Private Sub MenuLight_Click(sender As Object, e As EventArgs) Handles MenuLight.Click
    SftStyle1.DarkMode = DarkModeEnum.Off
End Sub
Private Sub MenuDark_Click(sender As Object, e As EventArgs) Handles MenuDark.Click
    SftStyle1.DarkMode = DarkModeEnum.On
End Sub
Private Sub MenuWindows_Click(sender As Object, e As EventArgs) Handles MenuWindows.Click
    SftStyle1.DarkMode = DarkModeEnum.Auto
End Sub

Back to Light

A switch back to light restores every color and setting the component changed, so the forms look as they did before they were styled. Those properties get the values they had before the switch to dark mode: on the .NET Framework, an application that changes one of them while the forms are dark, for example the BackColor of a text box that had a system color, sets it again after the switch back, in the SftStyle.DarkModeChanged or SftStyle.HighContrastChanged event.

New Forms and Controls

A form created while dark mode is active is styled before it first appears, so it never shows in light colors first. Controls added to an open form, for example a tab page added while the form is dark, are styled when they are added.

Thread

The component makes the switch, and raises the two events, on the thread that created it, the application's user interface thread, also when Windows reports the change of its setting on another thread.