HeaderPane
Main
Hide
Share Link
Print

EventViewer Sample (VB.NET)

This sample logs the events of an amount with up and down buttons and the popup calculator and of a part number with autocomplete and an ellipsis button. Its CustomValidation event handler refuses amounts over 10,000, and while the check box is set, its CalculatorOpening event handler cancels the calculator.

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

Imports System.ComponentModel
Imports System.Reflection
Imports Softelvdm.SftMaskNET

Public Class Form1

    Public Sub New()
        InitializeComponent()
        SftMask1.Value = 125.5D
        SftMask2.AutoComplete.Seed(New String() {"AB-1001", "AB-1002", "AC-2040", "BX-0815", "BX-0900", "CD-3141"})
    End Sub

    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
        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

    ' SftMask1 - an amount with up and down buttons; typing +, -, * or / opens the calculator

    Private Sub SftMask1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask1.TextChanged
        DumpValues("SftMask1.TextChanged (" + SftMask1.Text + ")", e)
    End Sub

    Private Sub SftMask1_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask1.ValueChanged
        Dim value As String = "none"
        If SftMask1.Value.HasValue Then
            value = SftMask1.Value.Value.ToString()
        End If
        DumpValues("SftMask1.ValueChanged (" + value + ")", e)
    End Sub

    Private Sub SftMask1_InputRejected(ByVal sender As Object, ByVal e As InputRejectedEventArgs) Handles SftMask1.InputRejected
        DumpValues("SftMask1.InputRejected", e)
    End Sub

    Private Sub SftMask1_ValidationError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs) Handles SftMask1.ValidationError
        DumpValues("SftMask1.ValidationError", e)
    End Sub

    ' Amounts over 10,000 are not accepted.
    Private Sub SftMask1_CustomValidation(ByVal sender As Object, ByVal e As CancelEventArgs) Handles SftMask1.CustomValidation
        e.Cancel = SftMask1.Value.HasValue AndAlso SftMask1.Value.Value > 10000
        DumpValues("SftMask1.CustomValidation" + If(e.Cancel, " (over 10,000, refused)", ""), e)
    End Sub

    Private Sub SftMask1_UpDownPress(ByVal sender As Object, ByVal e As UpDownPressEventArgs) Handles SftMask1.UpDownPress
        DumpValues("SftMask1.UpDownPress", e)
    End Sub

    Private Sub SftMask1_CalculatorOpening(ByVal sender As Object, ByVal e As CalculatorOpeningEventArgs) Handles SftMask1.CalculatorOpening
        e.Cancel = CheckBlock.Checked
        DumpValues("SftMask1.CalculatorOpening" + If(e.Cancel, " (canceled)", ""), e)
    End Sub

    Private Sub SftMask1_DropDownOpened(ByVal sender As Object, ByVal e As DropDownEventArgs) Handles SftMask1.DropDownOpened
        DumpValues("SftMask1.DropDownOpened", e)
    End Sub

    Private Sub SftMask1_DropDownClosed(ByVal sender As Object, ByVal e As DropDownEventArgs) Handles SftMask1.DropDownClosed
        DumpValues("SftMask1.DropDownClosed", e)
    End Sub

    Private Sub SftMask1_PrePaste(ByVal sender As Object, ByVal e As PrePasteEventArgs) Handles SftMask1.PrePaste
        DumpValues("SftMask1.PrePaste", e)
    End Sub

    Private Sub SftMask1_InputModeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask1.InputModeChanged
        DumpValues("SftMask1.InputModeChanged (" + If(SftMask1.Overtype, "overtype", "insert") + ")", e)
    End Sub

    Private Sub SftMask1_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask1.Enter
        DumpValues("SftMask1.Enter", e)
    End Sub

    Private Sub SftMask1_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask1.Leave
        DumpValues("SftMask1.Leave", e)
    End Sub

    Private Sub SftMask1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SftMask1.KeyDown
        DumpValues("SftMask1.KeyDown", e)
    End Sub

    ' SftMask2 - a part number; typing suggests earlier entries, the ellipsis button raises EllipseClick

    Private Sub SftMask2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask2.TextChanged
        DumpValues("SftMask2.TextChanged (" + SftMask2.Text + ")", e)
    End Sub

    Private Sub SftMask2_InputRejected(ByVal sender As Object, ByVal e As InputRejectedEventArgs) Handles SftMask2.InputRejected
        DumpValues("SftMask2.InputRejected", e)
    End Sub

    Private Sub SftMask2_ValidationError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs) Handles SftMask2.ValidationError
        DumpValues("SftMask2.ValidationError", e)
    End Sub

    Private Sub SftMask2_EllipseClick(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask2.EllipseClick
        DumpValues("SftMask2.EllipseClick", e)
    End Sub

    Private Sub SftMask2_DropDownOpened(ByVal sender As Object, ByVal e As DropDownEventArgs) Handles SftMask2.DropDownOpened
        DumpValues("SftMask2.DropDownOpened", e)
    End Sub

    Private Sub SftMask2_DropDownClosed(ByVal sender As Object, ByVal e As DropDownEventArgs) Handles SftMask2.DropDownClosed
        DumpValues("SftMask2.DropDownClosed", e)
    End Sub

    Private Sub SftMask2_AutoCompleteAccept(ByVal sender As Object, ByVal e As AutoCompleteAcceptEventArgs) Handles SftMask2.AutoCompleteAccept
        DumpValues("SftMask2.AutoCompleteAccept", e)
    End Sub

    Private Sub SftMask2_PrePaste(ByVal sender As Object, ByVal e As PrePasteEventArgs) Handles SftMask2.PrePaste
        DumpValues("SftMask2.PrePaste", e)
    End Sub

    Private Sub SftMask2_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask2.Enter
        DumpValues("SftMask2.Enter", e)
    End Sub

    Private Sub SftMask2_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles SftMask2.Leave
        DumpValues("SftMask2.Leave", e)
    End Sub

    Private Sub SftMask2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SftMask2.KeyDown
        DumpValues("SftMask2.KeyDown", e)
    End Sub

End Class