Ribbon for WinForms
ステータスバー
要素 > ステータスバー

The C1StatusBar control appears like a horizontal bar at the bottom of the Forms window. The StatusBar can display various kinds of status information in an application window.

The C1StatusBar control is a separate control and can be added at design-time from the Toolbox. When dropped on the Forms, C1StatusBar gets docked at the bottom. Items can be added to the left and right pane of the StatusBar by using the floating toolbar in context menu or the collection editors in the Properties window. For more information about adding items through the designer, refer this topic.

The StatusBar control can also be added to the form programmatically. The items can be added to the left pane and right pane of the StatusBar using the LeftPaneItems and RightPaneItems properties of the C1StatusBar class.

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
public partial class Form1 : Form
{ 
    C1StatusBar statusBar;
    int[] _percents = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 150, 200, 250, 300, 400, 700, 1000 };
    public Form1()
    {
        InitializeComponent();
        //ステータスバーをリボンコントロールに追加します
        AddStatusBar(this);            
    }

    public void AddStatusBar(Form1 form1)
    {
        
        //ステータスバーを作成して追加します
        statusBar = new C1StatusBar();
        statusBar.Width = 150;

        //パーセンテージ値を表示するボタンを作成します
        RibbonButton zoomButton = new RibbonButton(null, Image.FromFile("images\\zoomButton.png"));
        RibbonLabel wordcountLabel = new RibbonLabel();
        wordcountLabel.Text = "0 words";
        RibbonLabel charcountLabel = new RibbonLabel();
        charcountLabel.Text = "0 chars";

        //TextChangedイベントハンドラーを追加します
        richTextBox1.TextChanged += RichTextBox1_TextChanged;

        //リボントラックバーを作成します
        RibbonTrackBar zoomTrackBar = new RibbonTrackBar();
        zoomTrackBar.Minimum = 0;
        zoomTrackBar.Maximum = 17;
        zoomTrackBar.StepFrequency = 1;

        //イベントハンドラーを追加します
        zoomTrackBar.ValueChanged += ZoomTrackBar1_ValueChanged;

        //アイテムを左右のパネルに追加します
        statusBar.RightPaneItems.Add(zoomTrackBar);
        statusBar.RightPaneItems.Add(new RibbonLabel("10%"));
        statusBar.LeftPaneItems.Add(wordcountLabel);
        statusBar.LeftPaneItems.Add(charcountLabel);

        //ステータスバーをメインフォームに追加します
        this.Controls.Add(statusBar);

    }
    
    private void ZoomTrackBar1_ValueChanged(object sender, EventArgs e)
    {
        RibbonTrackBar zoomBar = (RibbonTrackBar)sender;
        var index = zoomBar.Value;
        int zf = _percents[index];
        var zoomLabel = (RibbonLabel)statusBar.RightPaneItems[1];
        zoomLabel.Text = zf.ToString() + "%";
        this.richTextBox1.ZoomFactor = zf / 100f;
    }
    private void RichTextBox1_TextChanged(object sender, EventArgs e)
    {            
        RibbonLabel charcountLabel = (RibbonLabel)statusBar.LeftPaneItems[0];
        RibbonLabel wordcountLabel = (RibbonLabel)statusBar.LeftPaneItems[1];
        charcountLabel.Text = richTextBox1.TextLength.ToString() + " chars";
        wordcountLabel.Text = richTextBox1.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length.ToString() + " words";
    }
    
}