HeaderPane
Main
Hide
Share Link
Print

Scaling Event, SftStyle Class

Occurs before a form or a control is scaled for the DPI of its monitor.

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

Syntax

public event EventHandler<ScalingEventArgs> Scaling;
Public Event Scaling As EventHandler(Of ScalingEventArgs)

Comments

Occurs before a form or a control is scaled for the DPI of its monitor.

On .NET Framework, in an application that is per-monitor DPI aware, SftStyle scales a top-level form that opens on a monitor with a different scale factor than the one it was laid out for, together with the fonts of its controls, and gives the controls that Windows Forms leaves with a small font after a form moves to another monitor their rescaled font. The event occurs for the form before it is scaled and for each control whose font SftStyle changes, before the change. Set Cancel to True in the event data to leave the form, with its controls, or the control as Windows Forms made it.

The event does not occur on .NET 10 and later, where Windows Forms scales the forms itself.

Examples

C# View entire sample code

        // Occurs for each control before it is styled; the event list can be left as it is.
        private void sftStyle1_Styling(object sender, StylingEventArgs e) {
            e.Cancel = checkLeaveList.Checked && e.Control == listView1;
            DumpValues("sftStyle1.Styling" + (e.Cancel ? " (left as it is)" : ""), e);
        }

        // Occurs on .NET Framework before a form or a control is scaled for the DPI of its monitor.
        private void sftStyle1_Scaling(object sender, ScalingEventArgs e) {
            DumpValues("sftStyle1.Scaling", e);
        }

        // sftSlider1 - a value; sftSlider2 - a range with two thumbs

        private void sftSlider1_ValueChanged(object sender, EventArgs e) {
            DumpValues("sftSlider1.ValueChanged (" + sftSlider1.Value + ")", e);
        }

VB.NET View entire sample code

    ' 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)
    End Sub

    ' SftSlider1 - a value; SftSlider2 - a range with two thumbs

    Private Sub SftSlider1_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftSlider1.ValueChanged
        DumpValues("SftSlider1.ValueChanged (" + SftSlider1.Value.ToString() + ")", e)
    End Sub

See Also SftStyle Class | Classes | SftStyle/NET 3.0