Public Class Form1
Private statusBar As C1StatusBar
Private _percents As Integer() = New Integer() {10, 20, 30, 40, 50, 60,
70, 80, 90, 100, 120, 150,
200, 250, 300, 400, 700, 1000}
Public Sub New()
InitializeComponent()
'ステータスバーをリボンコントロールに追加します
AddStatusBar(Me)
End Sub
Public Sub AddStatusBar(form1 As Form1)
'ステータスバーを作成して追加します
statusBar = New C1StatusBar()
statusBar.Width = 150
'パーセンテージ値を表示するボタンを作成します
Dim zoomButton As New RibbonButton(Nothing, Image.FromFile("images\zoomButton.png"))
Dim wordcountLabel As New RibbonLabel()
wordcountLabel.Text = "0 words"
Dim charcountLabel As New RibbonLabel()
charcountLabel.Text = "0 chars"
'TextChangedイベントハンドラーを追加します
AddHandler RichTextBox1.TextChanged, AddressOf RichTextBox1_TextChanged
'リボントラックバーを作成します
Dim zoomTrackBar As New RibbonTrackBar()
zoomTrackBar.Minimum = 0
zoomTrackBar.Maximum = 17
zoomTrackBar.StepFrequency = 1
'イベントハンドラーを追加します
AddHandler zoomTrackBar.ValueChanged, AddressOf ZoomTrackBar1_ValueChanged
'アイテムを左右のパネルに追加します
statusBar.RightPaneItems.Add(zoomTrackBar)
statusBar.RightPaneItems.Add(New RibbonLabel("10%"))
statusBar.LeftPaneItems.Add(wordcountLabel)
statusBar.LeftPaneItems.Add(charcountLabel)
'ステータスバーをメインフォームに追加します
Me.Controls.Add(statusBar)
End Sub
Private Sub ZoomTrackBar1_ValueChanged(sender As Object, e As EventArgs)
Dim zoomBar As RibbonTrackBar = DirectCast(sender, RibbonTrackBar)
Dim index = zoomBar.Value
Dim zf As Integer = _percents(index)
Dim zoomLabel = DirectCast(statusBar.RightPaneItems(1), RibbonLabel)
zoomLabel.Text = zf.ToString() & "%"
Me.RichTextBox1.ZoomFactor = zf / 100.0F
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs)
Dim charcountLabel As RibbonLabel = DirectCast(statusBar.LeftPaneItems(0), RibbonLabel)
Dim wordcountLabel As RibbonLabel = DirectCast(statusBar.LeftPaneItems(1), RibbonLabel)
charcountLabel.Text = RichTextBox1.TextLength.ToString() & " chars"
wordcountLabel.Text = RichTextBox1.Text.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries).Length.ToString() & " words"
End Sub
End Class