HeaderPane
Main
Hide
Share Link
Print

Styling Event, SftStyle Class

Occurs before a control is styled.

Class: SftStyle
Namespace: Softelvdm.SftStyleNET
Assembly: Softelvdm.SftStyleNET

Syntax

public event EventHandler<StylingEventArgs> Styling;
Public Event Styling As EventHandler(Of StylingEventArgs)

Comments

Occurs before a control is styled.

Set Cancel to True in the event data to leave the control as it is. Its child controls are styled independently. Colors the control inherits from its parent (a BackColor or ForeColor it does not set itself) still follow the dark parent; give it colors of its own to keep it light. Native menus, tool strips drawn with the ToolStripManager renderer and tooltips are styled for the whole application, so the event cannot leave them out.

On .NET 10 and later, the dark mode of Windows Forms itself still applies to the control; SftStyle leaves it out of the refresh of open forms and of what it adds to that dark mode. There the event also occurs for the controls of the open forms when the component starts or switches to light mode.

Examples

VB.NET View entire sample code

        DumpValues("SftStyle1.DarkModeChanged (" + If(SftStyle1.DarkModeActive, "dark", "light") + ")", e)
    End Sub

    Private Sub SftStyle1_HighContrastChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftStyle1.HighContrastChanged
        DumpValues("SftStyle1.HighContrastChanged (" + If(SftStyle1.HighContrastActive, "on", "off") + ")", e)
    End Sub

    ' Occurs for each control before it is styled; the event list can be left as it is.
    Private Sub SftStyle1_Styling(ByVal sender As Object, ByVal e As StylingEventArgs) Handles SftStyle1.Styling
        e.Cancel = CheckLeaveList.Checked AndAlso e.Control Is ListView1
        DumpValues("SftStyle1.Styling" + If(e.Cancel, " (left as it is)", ""), e)
    End Sub

    ' Occurs on .NET Framework before a form or a control is scaled for the DPI of its monitor.
    Private Sub SftStyle1_Scaling(ByVal sender As Object, ByVal e As ScalingEventArgs) Handles SftStyle1.Scaling
        DumpValues("SftStyle1.Scaling", e)

See Also SftStyle Class | Classes | SftStyle/NET 3.0