Option Explicit On 

Imports AxSftBoxLib45
Imports SftBoxLib45
Imports Softelvdm.OLEConvert

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private fontNamesDirection As SftBoxSortConstants = SftBoxSortConstants.sortSftBoxAscending
    Private fontStylesDirection As SftBoxSortConstants = SftBoxSortConstants.sortSftBoxAscending
    Private fontSizesDirection As SftBoxSortConstants = SftBoxSortConstants.sortSftBoxAscending

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
Friend WithEvents condHeaders As System.Windows.Forms.CheckBox
Friend WithEvents label3 As System.Windows.Forms.Label
Friend WithEvents panel1 As System.Windows.Forms.Panel
Friend WithEvents sampleText As System.Windows.Forms.Label
Friend WithEvents fontSizes As AxSftBoxLib45.AxSftBox
Friend WithEvents fontStyles As AxSftBoxLib45.AxSftBox
Friend WithEvents fontNames As AxSftBoxLib45.AxSftBox
Friend WithEvents label1 As System.Windows.Forms.Label
Friend WithEvents closeButton As System.Windows.Forms.Button
Friend WithEvents label5 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.condHeaders = New System.Windows.Forms.CheckBox
Me.label3 = New System.Windows.Forms.Label
Me.panel1 = New System.Windows.Forms.Panel
Me.sampleText = New System.Windows.Forms.Label
Me.fontSizes = New AxSftBoxLib45.AxSftBox
Me.fontStyles = New AxSftBoxLib45.AxSftBox
Me.fontNames = New AxSftBoxLib45.AxSftBox
Me.label1 = New System.Windows.Forms.Label
Me.closeButton = New System.Windows.Forms.Button
Me.label5 = New System.Windows.Forms.Label
Me.panel1.SuspendLayout()
CType(Me.fontSizes, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.fontStyles, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.fontNames, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'condHeaders
'
Me.condHeaders.Checked = True
Me.condHeaders.CheckState = System.Windows.Forms.CheckState.Checked
Me.condHeaders.Location = New System.Drawing.Point(7, 250)
Me.condHeaders.Name = "condHeaders"
Me.condHeaders.Size = New System.Drawing.Size(212, 23)
Me.condHeaders.TabIndex = 17
Me.condHeaders.Text = "Always show headers."
'
'label3
'
Me.label3.Location = New System.Drawing.Point(7, 204)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(475, 38)
Me.label3.TabIndex = 16
Me.label3.Text = "Click on the header buttons in the combo box to sort entries.  Make sure the comb" & _
    "o box is dropped down so you can see the sorting take place."
'
'panel1
'
Me.panel1.BackColor = System.Drawing.Color.White
Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.panel1.Controls.Add(Me.sampleText)
Me.panel1.Location = New System.Drawing.Point(146, 106)
Me.panel1.Name = "panel1"
Me.panel1.Size = New System.Drawing.Size(190, 91)
Me.panel1.TabIndex = 15
'
'sampleText
'
Me.sampleText.Location = New System.Drawing.Point(0, 23)
Me.sampleText.Name = "sampleText"
Me.sampleText.Size = New System.Drawing.Size(190, 68)
Me.sampleText.TabIndex = 0
Me.sampleText.Text = "AaBbCcYyZz"
Me.sampleText.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'fontSizes
'
Me.fontSizes.Location = New System.Drawing.Point(402, 57)
Me.fontSizes.Name = "fontSizes"
Me.fontSizes.OcxState = CType(resources.GetObject("fontSizes.OcxState"), System.Windows.Forms.AxHost.State)
Me.fontSizes.Size = New System.Drawing.Size(80, 40)
Me.fontSizes.TabIndex = 14
'
'fontStyles
'
Me.fontStyles.Location = New System.Drawing.Point(278, 57)
Me.fontStyles.Name = "fontStyles"
Me.fontStyles.OcxState = CType(resources.GetObject("fontStyles.OcxState"), System.Windows.Forms.AxHost.State)
Me.fontStyles.Size = New System.Drawing.Size(117, 40)
Me.fontStyles.TabIndex = 13
'
'fontNames
'
Me.fontNames.Location = New System.Drawing.Point(7, 59)
Me.fontNames.Name = "fontNames"
Me.fontNames.OcxState = CType(resources.GetObject("fontNames.OcxState"), System.Windows.Forms.AxHost.State)
Me.fontNames.Size = New System.Drawing.Size(263, 38)
Me.fontNames.TabIndex = 12
'
'label1
'
Me.label1.Location = New System.Drawing.Point(7, 8)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(380, 37)
Me.label1.TabIndex = 11
Me.label1.Text = "Easily add font selection to your applications (even on tool bars) using SftBox/O" & _
    "CX's font capabilities."
'
'closeButton
'
Me.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.closeButton.Location = New System.Drawing.Point(395, 8)
Me.closeButton.Name = "closeButton"
Me.closeButton.Size = New System.Drawing.Size(87, 30)
Me.closeButton.TabIndex = 10
Me.closeButton.Text = "Close"
'
'label5
'
Me.label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.label5.Location = New System.Drawing.Point(176, 248)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(304, 32)
Me.label5.TabIndex = 18
Me.label5.Text = "Click on the SftBox/OCX control above and hit F1 to access help information for S" & _
    "ftBox/OCX 4.5"
Me.label5.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.closeButton
Me.ClientSize = New System.Drawing.Size(487, 285)
Me.Controls.Add(Me.label5)
Me.Controls.Add(Me.condHeaders)
Me.Controls.Add(Me.label3)
Me.Controls.Add(Me.panel1)
Me.Controls.Add(Me.fontSizes)
Me.Controls.Add(Me.fontStyles)
Me.Controls.Add(Me.fontNames)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.closeButton)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "Softel vdm, Inc. - FontDlg Sample"
Me.panel1.ResumeLayout(False)
CType(Me.fontSizes, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.fontStyles, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.fontNames, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

'--locate-marker--

Private Sub closeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeButton.Click
    Application.Exit()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' add all font information
    UpdateFontNames()
End Sub

Private Sub UpdateFontNames()
    ' add all font names
    fontNames.BulkUpdate = True
    fontNames.Items.Clear()
    fontNames.Items.AddFontNames(-1, SftBoxFontConstants.fontSftBoxAll, True, 0)
    fontNames.Items.Selection = 0
    PerformSort(fontNames, SftBoxSortConstants.sortSftBoxAscending)
    fontNames.BulkUpdate = False
    fontNames.Columns.MakeOptimal(0)
    fontNames.Items.RecalcHorizontalExtent(0)
End Sub

Private Sub UpdateFontStyles()
    ' add all styles for the current font name
    If fontNames.Items.Selection >= 0 Then
        Dim OldText As String = fontStyles.Edit.Text
        fontStyles.Items.AddFontStyles(fontNames.get_Cell(fontNames.Items.Selection, 0).Text, 0, "", "")
        Dim index As Integer = fontStyles.Items.Find(OldText, 0, 0, False, True, True)
        If index < 0 Then index = 0
        fontStyles.Items.Selection = index
    Else
        fontStyles.Items.Clear()
    End If
    PerformSort(fontStyles, SftBoxSortConstants.sortSftBoxAscending)
    fontStyles.Columns.MakeOptimal(0)
    fontStyles.Items.RecalcHorizontalExtent(0)
End Sub

Private Sub UpdateFontSizes()
    ' add all sizes for the current font name
    If fontNames.Items.Selection >= 0 Then
        Dim OldText As String = fontSizes.Edit.Text
        fontSizes.Items.AddFontSizes(fontNames.get_Cell(fontNames.Items.Selection, 0).Text, 0)
        Dim index As Integer = fontSizes.Items.Find(OldText, 0, 0, False, True, True)
        If index < 0 Then index = 0
        fontSizes.Items.Selection = index
    Else
        fontSizes.Items.Clear()
    End If
    PerformSort(fontSizes, SftBoxSortConstants.sortSftBoxAscending)
    fontSizes.Columns.MakeOptimal(0)
    fontSizes.Items.RecalcHorizontalExtent(0)
    UpdateSample()
End Sub

Private Sub fontNames_SelectionChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles fontNames.SelectionChange
    UpdateFontStyles()
End Sub

Private Sub fontStyles_SelectionChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles fontStyles.SelectionChange
    UpdateFontSizes()
End Sub

Private Sub fontSizes_SelectionChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles fontSizes.SelectionChange
    UpdateSample()
End Sub

Private Sub UpdateSample()
    Dim SelItem As Integer = fontStyles.Items.Selection
    If SelItem >= 0 And fontSizes.Edit.Text <> "" Then
        sampleText.Text = "AaBbCcYyZz"
        Dim style As FontStyle = 0
        If (fontStyles.get_Cell(SelItem, 0).Data And &H80000000&) <> 0 Then style = style Or FontStyle.Italic
        Dim weight As Integer = fontStyles.get_Cell(SelItem, 0).Data And &H7FFFFFFF&
        If weight > 400 Then style = style Or FontStyle.Bold
        sampleText.Font = New Font(fontNames.Edit.Text, Convert.ToSingle(fontSizes.Edit.Text), style)
    Else
        sampleText.Text = ""
    End If
End Sub

Private Sub condHeaders_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles condHeaders.CheckedChanged
    ' if this event occurs during form initialization, the activeX control
    ' may not yet be initialized completely, so we have to check for GetOcx()
    If Not fontNames.GetOcx() Is Nothing Then
        If condHeaders.Checked Then
            fontNames.Headers.Main = True
            fontNames.Headers.DropDown = False
            fontStyles.Headers.Main = True
            fontStyles.Headers.DropDown = False
            fontSizes.Headers.Main = True
            fontSizes.Headers.DropDown = False
        Else
            fontNames.Headers.Main = False
            fontNames.Headers.DropDown = True
            fontStyles.Headers.Main = False
            fontStyles.Headers.DropDown = True
            fontSizes.Headers.Main = False
            fontSizes.Headers.DropDown = True
        End If
    End If
End Sub

Private Sub PerformSort(ByVal box As AxSftBox, ByVal currDirection As SftBoxSortConstants)
    If currDirection = SftBoxSortConstants.sortSftBoxAscending Then
        box.get_Header(0).Image.Appearance = SftPictureImageConstants.sftImageSortAsc
    Else
        box.get_Header(0).Image.Appearance = SftPictureImageConstants.sftImageSortDesc
    End If
    ' Font styles and font names are sorted by Cell.Text property
    ' Font sizes are sorted according to numeric Cell.Data property
    ' Outside of this function, only sortSftBoxAscending and sortSftBoxDescending
    ' are used, so we need to translate these
    If box Is fontSizes Then
        If currDirection = SftBoxSortConstants.sortSftBoxAscending Then
            currDirection = SftBoxSortConstants.sortSftBoxCellValueAscending
        Else
            currDirection = SftBoxSortConstants.sortSftBoxCellValueDescending
        End If
    End If
    box.Items.Sort(-1, 0, currDirection)
End Sub

Private Sub ReverseSortOrder(ByVal box As AxSftBox, ByRef currDirection As SftBoxSortConstants)
    If currDirection = SftBoxSortConstants.sortSftBoxAscending Then
        currDirection = SftBoxSortConstants.sortSftBoxDescending
    Else
        currDirection = SftBoxSortConstants.sortSftBoxAscending
    End If
End Sub

Private Sub fontNames_ItemClick(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemClickEvent) Handles fontNames.ItemClick
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontNames, fontNamesDirection)
        PerformSort(fontNames, fontNamesDirection)
    End If
End Sub

Private Sub fontNames_ItemDblClk(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemDblClkEvent) Handles fontNames.ItemDblClk
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontNames, fontNamesDirection)
        PerformSort(fontNames, fontNamesDirection)
    End If
End Sub

Private Sub fontStyles_ItemClick(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemClickEvent) Handles fontStyles.ItemClick
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontStyles, fontStylesDirection)
        PerformSort(fontStyles, fontStylesDirection)
    End If
End Sub

Private Sub fontStyles_ItemDblClk(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemDblClkEvent) Handles fontStyles.ItemDblClk
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontStyles, fontStylesDirection)
        PerformSort(fontStyles, fontStylesDirection)
    End If
End Sub

Private Sub fontSizes_ItemClick(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemClickEvent) Handles fontSizes.ItemClick
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontSizes, fontSizesDirection)
        PerformSort(fontSizes, fontSizesDirection)
    End If
End Sub

Private Sub fontSizes_ItemDblClk(ByVal sender As Object, ByVal e As AxSftBoxLib45._ISftBoxEvents_ItemDblClkEvent) Handles fontSizes.ItemDblClk
    If e.areaType = SftBoxAreaConstants.areaSftBoxColumn Then
        ReverseSortOrder(fontSizes, fontSizesDirection)
        PerformSort(fontSizes, fontSizesDirection)
    End If
End Sub

End Class