HeaderPane
Main
Hide
Share Link
Print

EventViewer Sample (VB.NET)

This sample logs the events of the SftStyle component, of a slider and a range slider, of a task dialog page with radio buttons, a verification check box, an expander, a link, an Apply button that keeps the dialog open and a Help button, and of the color dialog with its Help button. While the Leave the event list as it is check box is set, the Styling event handler leaves the event list as it is in dark mode. On the .NET Framework the Scaling event is logged when a form moves to a monitor with another scale factor.

The source code is located at C:\Program Files (x86)\Softelvdm\SftStyle NET 3.0\Samples\VB\EventViewer\Form1.vb.

Imports System.Reflection
Imports Softelvdm.SftStyleNET
Imports Softelvdm.SftStyleNET.Controls

Public Class Form1

    Private strLastEvent As String = ""
    Private fLastEventDup As Boolean = False

    ' This is a small helper routine to show all properties and fields of an object
    Private Sub DumpValues(ByVal title As String, ByVal o As Object)

        Dim s As String = ""

        If strLastEvent = title Then
            If Not fLastEventDup Then
                s = "Additional " + title + " events ... now suppressed"
                fLastEventDup = True
            Else
                Return
            End If
        Else
            strLastEvent = title
            fLastEventDup = False

            Dim api() As PropertyInfo = o.GetType().GetProperties()
            For Each pi As PropertyInfo In api
                s += pi.Name + "=" + Describe(pi.GetValue(o, New Object() {})) + " "
            Next
            Dim afi() As FieldInfo = o.GetType().GetFields()
            For Each fi As FieldInfo In afi
                s += fi.Name + "=" + Describe(fi.GetValue(o)) + " "
            Next
        End If

        Dim item As ListViewItem = ListView1.Items.Add(New ListViewItem(New String() {title, s}))
        ListView1.SelectedItems.Clear()
        item.Selected = True
        item.EnsureVisible()
    End Sub

    Private Function Describe(ByVal value As Object) As String
        If value Is Nothing Then
            Return "Nothing"
        End If
        Dim c As Control = TryCast(value, Control)
        If c IsNot Nothing Then
            Return c.GetType().Name + " " + c.Name
        End If
        Return value.ToString()
    End Function

    Private Sub ButtonClear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonClear.Click
        ListView1.Items.Clear()
        strLastEvent = ""
        fLastEventDup = False
    End Sub

    ' SftStyle1 - the mode of every form of the application; the check box switches it

    Private Sub CheckDark_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CheckDark.CheckedChanged
        Dim mode As DarkModeEnum = If(CheckDark.Checked, DarkModeEnum.On, DarkModeEnum.Off)
        SftStyle1.DarkMode = mode
        SftSlider1.DarkMode = mode
        SftSlider2.DarkMode = mode
    End Sub

    Private Sub SftStyle1_DarkModeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftStyle1.DarkModeChanged
        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)
    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

    Private Sub SftSlider1_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles SftSlider1.Scroll
        DumpValues("SftSlider1.Scroll", e)
    End Sub

    Private Sub SftSlider2_RangeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftSlider2.RangeChanged
        DumpValues("SftSlider2.RangeChanged (" + SftSlider2.LowerValue.ToString() + " to " + SftSlider2.UpperValue.ToString() + ")", e)
    End Sub

    Private Sub SftSlider2_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftSlider2.ValueChanged
        DumpValues("SftSlider2.ValueChanged (" + SftSlider2.LowerValue.ToString() + ")", e)
    End Sub

    Private Sub SftSlider2_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles SftSlider2.Scroll
        DumpValues("SftSlider2.Scroll", e)
    End Sub

    ' A task dialog page with every kind of element; Apply keeps the dialog open.
    Private Sub ButtonTaskDialog_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonTaskDialog.Click
        Dim page As New SftTaskDialogPage()
        page.Caption = "Export"
        page.Heading = "Choose the export format"
        page.Text = "The report covers 1,284 orders. Read the <a href=""formats"">format notes</a> first."
        page.EnableLinks = True
        page.Verification = New SftTaskDialogVerificationCheckBox("&Open the file after the export")
        page.Expander = New SftTaskDialogExpander("Comma-separated files open in any spreadsheet program; PDF keeps the layout of the report.")
        page.RadioButtons.Add("&Comma-separated values (.csv)").Checked = True
        page.RadioButtons.Add("&PDF document")
        Dim apply As New SftTaskDialogButton("&Apply")
        apply.AllowCloseDialog = False
        page.Buttons.Add(apply)
        page.Buttons.Add(SftTaskDialogButton.OK)
        page.Buttons.Add(SftTaskDialogButton.Cancel)
        page.Buttons.Add(SftTaskDialogButton.Help)

        AddHandler page.Created, Sub(s, a) DumpValues("page.Created", a)
        AddHandler page.Destroyed, Sub(s, a) DumpValues("page.Destroyed", a)
        AddHandler page.HelpRequest, Sub(s, a) DumpValues("page.HelpRequest", a)
        AddHandler page.LinkClicked, Sub(s, a) DumpValues("page.LinkClicked", a)
        AddHandler apply.Click, Sub(s, a) DumpValues("Apply.Click (the dialog stays open)", a)
        For Each radio As SftTaskDialogRadioButton In page.RadioButtons
            Dim r As SftTaskDialogRadioButton = radio
            AddHandler r.CheckedChanged, Sub(s, a) DumpValues("RadioButton.CheckedChanged (" + r.Text.Replace("&", "") + If(r.Checked, ", checked", "") + ")", a)
        Next
        AddHandler page.Verification.CheckedChanged, Sub(s, a) DumpValues("Verification.CheckedChanged (" + page.Verification.Checked.ToString() + ")", a)
        AddHandler page.Expander.ExpandedChanged, Sub(s, a) DumpValues("Expander.ExpandedChanged (" + page.Expander.Expanded.ToString() + ")", a)

        Dim clicked As SftTaskDialogButton = SftTaskDialog.ShowDialog(Me, page)
        DumpValues("SftTaskDialog.ShowDialog (" + clicked.Text.Replace("&", "") + ")", EventArgs.Empty)
    End Sub

    Private Sub ButtonColorDialog_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonColorDialog.Click
        Dim result As DialogResult = SftColorDialog1.ShowDialog(Me)
        DumpValues("SftColorDialog1.ShowDialog (" + result.ToString() + ", " + SftColorDialog1.Color.Name + ")", EventArgs.Empty)
    End Sub

    Private Sub SftColorDialog1_HelpRequest(ByVal sender As Object, ByVal e As EventArgs) Handles SftColorDialog1.HelpRequest
        DumpValues("SftColorDialog1.HelpRequest", e)
    End Sub

End Class