HeaderPane
Main
Hide
Share Link
Print

EventViewer Sample (VB.NET)

This sample inspects events generated by the tab control.

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

Imports System.Reflection
Imports Softelvdm.SftTabsNET

Public Class Form1

Private strLastEvent As String = ""
Private fLastEventDup As Boolean = False
Private addedTabs As Integer = 0

' 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

' Tabs are shown with their text instead of their class name
Private Function Describe(ByVal value As Object) As String
    Dim tab As TabClass = TryCast(value, TabClass)
    If tab IsNot Nothing Then
        Return """" + tab.Text + """"
    End If
    If value Is Nothing Then
        Return "Nothing"
    End If
    Return value.ToString()
End Function

Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
    addedTabs += 1
    Dim tab As TabClass = SftTabs1.Tabs.Add("Added " + addedTabs.ToString())
    tab.CloseButton = TabCloseButtonOptionalEnum.Always

    ' the page of the new tab is created by the control
    Dim info As New Label()
    info.AutoSize = True
    info.Location = New Point(12, 12)
    info.Text = "This tab was added by the Add Tab button. Its close button removes it."
    tab.Page.Controls.Add(info)

    tab.Select()
End Sub

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

Private Sub SftTabs1_Switching(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabSwitchingEventArgs) Handles SftTabs1.Switching
    DumpValues("Switching", e)

    ' e.Cancel = True would keep the current tab
End Sub

Private Sub SftTabs1_SwitchingDisabled(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabEventArgs) Handles SftTabs1.SwitchingDisabled
    DumpValues("SwitchingDisabled", e)
End Sub

Private Sub SftTabs1_Switched(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabSwitchedEventArgs) Handles SftTabs1.Switched
    DumpValues("Switched", e)
End Sub

Private Sub SftTabs1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.SelectedIndexChanged
    DumpValues("SelectedIndexChanged", e)
End Sub

Private Sub SftTabs1_Scrolled(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabScrolledEventArgs) Handles SftTabs1.Scrolled
    DumpValues("Scrolled", e)
End Sub

Private Sub SftTabs1_PartClicked(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabPartClickedEventArgs) Handles SftTabs1.PartClicked
    DumpValues("PartClicked", e)
End Sub

Private Sub SftTabs1_TabCloseButtonClicked(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabEventArgs) Handles SftTabs1.TabCloseButtonClicked
    DumpValues("TabCloseButtonClicked", e)

    ' the control does not remove the tab, the application does
    e.Tab.Remove()
End Sub

Private Sub SftTabs1_CloseButtonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.CloseButtonClicked
    DumpValues("CloseButtonClicked", e)

    ' the control's Close button removes the selected tab in this sample
    Dim tab As TabClass = SftTabs1.SelectedTab
    If tab IsNot Nothing Then
        tab.Remove()
    End If
End Sub

Private Sub SftTabs1_MinimizeButtonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MinimizeButtonClicked
    DumpValues("MinimizeButtonClicked", e)
End Sub

Private Sub SftTabs1_RestoreButtonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.RestoreButtonClicked
    DumpValues("RestoreButtonClicked", e)
End Sub

Private Sub SftTabs1_DragDetected(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabDragDetectedEventArgs) Handles SftTabs1.DragDetected
    DumpValues("DragDetected", e)

    ' e.Handled is left False, so the control lets the user move the tab (AllowReordering property)
End Sub

Private Sub SftTabs1_TabReordered(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabReorderedEventArgs) Handles SftTabs1.TabReordered
    DumpValues("TabReordered", e)
End Sub

Private Sub SftTabs1_TabAdded(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabEventArgs) Handles SftTabs1.TabAdded
    DumpValues("TabAdded", e)
End Sub

Private Sub SftTabs1_TabRemoved(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabEventArgs) Handles SftTabs1.TabRemoved
    DumpValues("TabRemoved", e)
End Sub

Private Sub SftTabs1_ShowToolTip(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabToolTipEventArgs) Handles SftTabs1.ShowToolTip
    DumpValues("ShowToolTip", e)

    If e.Area = TabHitAreaEnum.Tab AndAlso e.Tab IsNot Nothing AndAlso e.Tab.Text = "&Tooltips" Then
        e.ToolTipIcon = ToolTipIcon.Info
        e.ToolTipTitle = "Balloon Tooltip"
        e.ToolTipStyle = Softelvdm.SftTabsNET.Controls.ToolTipAppearanceEnum.Balloon
        e.ToolTipText = "A simple explanatory tooltip" + vbLf + "for just this tab"
    End If
End Sub

Private Sub SftTabs1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.Enter
    DumpValues("Enter", e)
End Sub

Private Sub SftTabs1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.Leave
    DumpValues("Leave", e)
End Sub

Private Sub SftTabs1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SftTabs1.KeyDown
    DumpValues("KeyDown", e)
End Sub

Private Sub SftTabs1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SftTabs1.KeyPress
    DumpValues("KeyPress", e)
End Sub

Private Sub SftTabs1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SftTabs1.KeyUp
    DumpValues("KeyUp", e)
End Sub

Private Sub SftTabs1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles SftTabs1.PreviewKeyDown
    DumpValues("PreviewKeyDown", e)
End Sub

Private Sub SftTabs1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseClick
    DumpValues("MouseClick", e)
End Sub

Private Sub SftTabs1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseDoubleClick
    DumpValues("MouseDoubleClick", e)
End Sub

Private Sub SftTabs1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseDown
    DumpValues("MouseDown", e)
End Sub

Private Sub SftTabs1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MouseEnter
    DumpValues("MouseEnter", e)
End Sub

Private Sub SftTabs1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MouseHover
    DumpValues("MouseHover", e)
End Sub

Private Sub SftTabs1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MouseLeave
    DumpValues("MouseLeave", e)
End Sub

Private Sub SftTabs1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseMove
    ' DumpValues("MouseMove", e)  ' deliberately suppressed
End Sub

Private Sub SftTabs1_MouseMoveHoverTimer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MouseMoveHoverTimer
    DumpValues("MouseMoveHoverTimer", e)
End Sub

Private Sub SftTabs1_MouseMoveTimer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MouseMoveTimer
    DumpValues("MouseMoveTimer", e)
End Sub

Private Sub SftTabs1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseUp
    DumpValues("MouseUp", e)
End Sub

Private Sub SftTabs1_MouseWheel(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SftTabs1.MouseWheel
    DumpValues("MouseWheel", e)
End Sub

' The control validates the control with the focus before the user switches to another tab
Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    If TextBox1.Text.Trim() = "" Then
        e.Cancel = True
        DumpValues("TextBox1 Validating (canceled, the text box is empty)", e)
    End If
End Sub

End Class