Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports C1.Win.C1Ribbon

Public Class DemoForm

    Private _internalFontChange As Boolean

    Public Sub New()

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

        ' Add any initialization after the InitializeComponent() call.
        Dim f As Font = label1.Font
        _internalFontChange = True
        fontEditor.SelectedFont = f
        numericUpDownHost1.Value = Convert.ToDecimal(f.SizeInPoints)
        _internalFontChange = False

        backColorEditor.SelectedColor = label1.BackColor
        foreColorEditor.SelectedColor = label1.ForeColor

        axWebBrowserHost1.Navigate(Application.StartupPath + "\..\..\Html\A plea for C++.htm")

    End Sub

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click, RibbonApplicationMenu1.DoubleClick
        Close()
    End Sub

    Private Sub pictureBoxHost1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pictureBoxHost1.Click
        MessageBox.Show("You clicked the Earth.", "Congratulations", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub numericUpDownHost1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numericUpDownHost1.ValueChanged
        If Not _internalFontChange Then
            Dim f As Font = label1.Font
            f = New Font(f.Name, Convert.ToSingle(numericUpDownHost1.Value), f.Style, f.Unit)
            _internalFontChange = True
            label1.Font = f
            fontEditor.SelectedFont = f
            _internalFontChange = False
        End If
        statusLabel.Text = String.Format("Number is {0}", numericUpDownHost1.Value)
    End Sub

    Private Sub checkedListBoxHost1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles checkedListBoxHost1.ItemCheck
        Dim coll As CheckedListBox.ObjectCollection = checkedListBoxHost1.Items
        Dim sb As StringBuilder = New StringBuilder()
        For i As Int32 = 0 To coll.Count - 1
            Dim isChecked As Boolean = False
            If i = e.Index Then
                If e.NewValue = CheckState.Checked Then
                    isChecked = True
                Else
                    isChecked = False
                End If
            Else
                isChecked = checkedListBoxHost1.GetItemChecked(i)
            End If
            If isChecked Then
                sb.Append(coll(i)).Append(", ")
            End If
        Next
        Dim res As String
        If sb.Length > 0 Then
            res = sb.ToString(0, sb.Length - 2)
            label1.Text = res
        Else
            res = "<none>"
            label1.Text = "Demo"
        End If
        checkStatusLabel.Text = "Checked: " + res
    End Sub

    Private Sub backColorEditor_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backColorEditor.SelectedColorChanged
        label1.BackColor = backColorEditor.SelectedColor
    End Sub

    Private Sub foreColorEditor_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles foreColorEditor.SelectedColorChanged
        label1.ForeColor = foreColorEditor.SelectedColor
    End Sub

    Private Sub fontEditor_SelectedFontChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fontEditor.SelectedFontChanged
        If Not _internalFontChange Then
            _internalFontChange = True
            label1.Font = fontEditor.SelectedFont
            numericUpDownHost1.Value = Convert.ToDecimal(fontEditor.SelectedFont.SizeInPoints)
            _internalFontChange = False
        End If
    End Sub

    Private Sub DemoForm_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        axWebBrowserHost1.Width = Width - 40
    End Sub
End Class
