HeaderPane
Main
Hide
Share Link
Print

DemoSample Sample (VB.NET)

This sample shows an overview of the tab control's features, with options that change its look, tab position, rows, buttons and other properties.

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

Imports System.Collections.Generic
Imports Softelvdm.SftTabsNET
Imports Softelvdm.SftTabsNET.Controls

Public Class Form1

Private loading As Boolean = False
Private minimized As Boolean = False
Private addedTabs As Integer = 0
Private tabImages As New Dictionary(Of TabClass, Image)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' the options show the properties as they were defined in the designer
    loading = True
    FillCombo(ComboLook, SftTabs1.Look)
    FillCombo(ComboPosition, SftTabs1.TabPosition)
    FillCombo(ComboOrientation, SftTabs1.TextOrientation)
    FillCombo(ComboAlignment, SftTabs1.TabAlignment)
    FillCombo(ComboCloseButton, SftTabs1.TabCloseButton)
    FillCombo(ComboDarkMode, SftTabs1.DarkMode)
    FillCombo(ComboLayout, SftTabs1.LayoutMode)
    CheckScrolling.Checked = SftTabs1.Scrolling.Enabled
    NumericRows.Value = SftTabs1.Rows
    CheckFixed.Checked = SftTabs1.Fixed
    CheckFill.Checked = SftTabs1.FillComplete
    CheckBold.Checked = SftTabs1.BoldSelected
    CheckFlyby.Checked = SftTabs1.FlybyHighlight
    CheckImages.Checked = True
    CheckReorder.Checked = SftTabs1.AllowReordering
    CheckButtons.Checked = SftTabs1.Buttons.CloseButton
    CheckToolTips.Checked = SftTabs1.ShowToolTips
    loading = False

    For Each tab As TabClass In SftTabs1.Tabs
        If tab.Image IsNot Nothing Then
            tabImages.Add(tab, tab.Image)
        End If
    Next
    UpdateOptions()
End Sub

Private Sub FillCombo(ByVal combo As ComboBox, ByVal current As Object)
    For Each value As Object In [Enum].GetValues(current.GetType())
        combo.Items.Add(value)
    Next
    combo.SelectedItem = current
End Sub

' options that have no effect with the current settings are disabled
Private Sub UpdateOptions()
    Dim scrolling As Boolean = SftTabs1.Scrolling.Enabled
    Dim autoFlow As Boolean = SftTabs1.LayoutMode = TabLayoutModeEnum.AutoFlow
    Dim oneRow As Boolean = scrolling OrElse (SftTabs1.Rows = 1 AndAlso Not autoFlow)
    ' tabs scroll in one row and not while they fill the row
    CheckScrolling.Enabled = SftTabs1.Rows = 1 AndAlso Not SftTabs1.FillComplete
    LabelRows.Enabled = Not scrolling AndAlso Not autoFlow
    NumericRows.Enabled = LabelRows.Enabled
    LabelLayout.Enabled = Not scrolling
    ComboLayout.Enabled = Not scrolling
    CheckFill.Enabled = Not scrolling
    ' tabs are reordered and the buttons are shown in one row only
    CheckReorder.Enabled = oneRow
    CheckButtons.Enabled = oneRow
    Dim look As TabLookEnum = SftTabs1.Look
    ButtonAccent.Enabled = look = TabLookEnum.Underline OrElse look = TabLookEnum.Document OrElse look = TabLookEnum.Pills
End Sub

Private Sub ComboLook_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboLook.SelectedIndexChanged
    If loading Then Return
    SftTabs1.Look = CType(ComboLook.SelectedItem, TabLookEnum)
    UpdateOptions()
End Sub

Private Sub ComboPosition_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboPosition.SelectedIndexChanged
    If loading Then Return
    RestorePages()
    SftTabs1.TabPosition = CType(ComboPosition.SelectedItem, TabPositionEnum)
End Sub

Private Sub ComboOrientation_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboOrientation.SelectedIndexChanged
    If loading Then Return
    SftTabs1.TextOrientation = CType(ComboOrientation.SelectedItem, TabTextOrientationEnum)
End Sub

Private Sub ComboAlignment_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboAlignment.SelectedIndexChanged
    If loading Then Return
    SftTabs1.TabAlignment = CType(ComboAlignment.SelectedItem, TabAlignmentEnum)
End Sub

Private Sub ComboCloseButton_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboCloseButton.SelectedIndexChanged
    If loading Then Return
    SftTabs1.TabCloseButton = CType(ComboCloseButton.SelectedItem, TabCloseButtonEnum)
End Sub

Private Sub ComboDarkMode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboDarkMode.SelectedIndexChanged
    If loading Then Return
    SftTabs1.DarkMode = CType(ComboDarkMode.SelectedItem, DarkModeEnum)
End Sub

Private Sub ComboLayout_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboLayout.SelectedIndexChanged
    If loading Then Return
    RestorePages()
    SftTabs1.LayoutMode = CType(ComboLayout.SelectedItem, TabLayoutModeEnum)
    UpdateOptions()
End Sub

Private Sub CheckScrolling_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckScrolling.CheckedChanged
    If loading Then Return
    RestorePages()
    SftTabs1.Scrolling.Enabled = CheckScrolling.Checked
    UpdateOptions()
End Sub

Private Sub NumericRows_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericRows.ValueChanged
    If loading Then Return
    RestorePages()
    SftTabs1.Rows = CInt(NumericRows.Value)
    UpdateOptions()
End Sub

Private Sub CheckFixed_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckFixed.CheckedChanged
    If loading Then Return
    SftTabs1.Fixed = CheckFixed.Checked
End Sub

Private Sub CheckFill_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckFill.CheckedChanged
    If loading Then Return
    SftTabs1.FillComplete = CheckFill.Checked
    UpdateOptions()
End Sub

Private Sub CheckBold_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBold.CheckedChanged
    If loading Then Return
    SftTabs1.BoldSelected = CheckBold.Checked
End Sub

Private Sub CheckFlyby_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckFlyby.CheckedChanged
    If loading Then Return
    SftTabs1.FlybyHighlight = CheckFlyby.Checked
End Sub

Private Sub CheckImages_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckImages.CheckedChanged
    If loading Then Return
    For Each entry As KeyValuePair(Of TabClass, Image) In tabImages
        entry.Key.Image = If(CheckImages.Checked, entry.Value, Nothing)
    Next
End Sub

Private Sub CheckReorder_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckReorder.CheckedChanged
    If loading Then Return
    SftTabs1.AllowReordering = CheckReorder.Checked
End Sub

Private Sub CheckButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckButtons.CheckedChanged
    If loading Then Return
    RestorePages()
    SftTabs1.Buttons.CloseButton = CheckButtons.Checked
    SftTabs1.Buttons.MinimizeButton = CheckButtons.Checked
    SftTabs1.Buttons.RestoreButton = CheckButtons.Checked
End Sub

Private Sub CheckToolTips_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckToolTips.CheckedChanged
    If loading Then Return
    SftTabs1.ShowToolTips = CheckToolTips.Checked
End Sub

Private Sub ButtonAccent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAccent.Click
    ColorDialog1.Color = SftTabs1.AccentColor
    If ColorDialog1.ShowDialog(Me) = DialogResult.OK Then
        SftTabs1.AccentColor = ColorDialog1.Color
    End If
End Sub

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.Dock = DockStyle.Fill
    info.Padding = New Padding(12)
    info.Text = "This tab was added by the Add Tab button. Its close button removes it."
    tab.Page.Controls.Add(info)
    SetPageColors()

    tab.Select()
End Sub

Private Sub SftTabs1_DarkModeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.DarkModeChanged
    SetPageColors()
End Sub

' the control paints the pages; the text color of the controls on the pages is the application's
Private Sub SetPageColors()
    Dim fore As Color = If(SftTabs1.DarkModeActive, Color.White, SystemColors.ControlText)
    For Each tab As TabClass In SftTabs1.Tabs
        tab.Page.ForeColor = fore
    Next
End Sub

Private Sub SftTabs1_TabCloseButtonClicked(ByVal sender As System.Object, ByVal e As Softelvdm.SftTabsNET.TabEventArgs) Handles SftTabs1.TabCloseButtonClicked
    ' the control does not remove the tab, the application does
    tabImages.Remove(e.Tab)
    e.Tab.Remove()
End Sub

Private Sub SftTabs1_CloseButtonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.CloseButtonClicked
    ' the control's Close button removes the selected tab in this sample
    Dim tab As TabClass = SftTabs1.SelectedTab
    If tab IsNot Nothing Then
        tabImages.Remove(tab)
        tab.Remove()
    End If
End Sub

Private Sub SftTabs1_MinimizeButtonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SftTabs1.MinimizeButtonClicked
    ' the control is reduced to its tabs; the panel behind it becomes visible
    If minimized Then Return
    Dim strip As Rectangle = SftTabs1.StripBounds
    Dim border As Size = SftTabs1.Size - SftTabs1.ClientSize
    Select Case SftTabs1.TabPosition
        Case TabPositionEnum.Top
            SftTabs1.Dock = DockStyle.Top
            SftTabs1.Height = strip.Height + border.Height
        Case TabPositionEnum.Bottom
            SftTabs1.Dock = DockStyle.Bottom
            SftTabs1.Height = strip.Height + border.Height
        Case TabPositionEnum.Left
            SftTabs1.Dock = DockStyle.Left
            SftTabs1.Width = strip.Width + border.Width
        Case TabPositionEnum.Right
            SftTabs1.Dock = DockStyle.Right
            SftTabs1.Width = strip.Width + border.Width
    End Select
    minimized = True
    SftTabs1.Buttons.MinimizeButtonEnabled = False
    SftTabs1.Buttons.RestoreButtonEnabled = True
End Sub

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

Private Sub RestorePages()
    If Not minimized Then Return
    SftTabs1.Dock = DockStyle.Fill
    minimized = False
    SftTabs1.Buttons.MinimizeButtonEnabled = True
    SftTabs1.Buttons.RestoreButtonEnabled = False
End Sub

End Class