Ribbon for WinForms | ComponentOne
Elements / Status Bar
In This Topic
    Status Bar
    In This Topic

    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.

    Statusbar

    Adding StatusBar at Design-Time

    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 dual floating toolbars or the collection editors in the Properties window.

    Adding StatusBar via Code

    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()
            'Add Status Bar to the Ribbon Control
            AddStatusBar(Me)
        End Sub
    
        Public Sub AddStatusBar(form1 As Form1)
            ' Create and Add a Status Bar
            statusBar = New C1StatusBar()
            statusBar.Width = 150
    
            ' Create button to show the percentage value
            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"
    
            ' Add TextChanged event handler
            AddHandler RichTextBox1.TextChanged, AddressOf RichTextBox1_TextChanged
    
            ' Create a Ribbon Track Bar
            Dim zoomTrackBar As New RibbonTrackBar()
            zoomTrackBar.Minimum = 0
            zoomTrackBar.Maximum = 17
            zoomTrackBar.StepFrequency = 1
    
            ' Add Event Handler
            AddHandler zoomTrackBar.ValueChanged, AddressOf ZoomTrackBar1_ValueChanged
    
            ' Add items to the right and left panels
            statusBar.RightPaneItems.Add(zoomTrackBar)
            statusBar.RightPaneItems.Add(New RibbonLabel("10%"))
            statusBar.LeftPaneItems.Add(wordcountLabel)
            statusBar.LeftPaneItems.Add(charcountLabel)
    
            ' Add Status Bar to the Main Form
            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();
            //Add Status Bar to the Ribbon Control
            AddStatusBar(this);            
        }
    
        public void AddStatusBar(Form1 form1)
        {
            
            // Create and Add a Status Bar
            statusBar = new C1StatusBar();
            statusBar.Width = 150;
    
            // Create button to show the percentage value
            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";
    
            // Add TextChanged event handler
            richTextBox1.TextChanged += RichTextBox1_TextChanged;
    
            // Create a Ribbon Track Bar
            RibbonTrackBar zoomTrackBar = new RibbonTrackBar();
            zoomTrackBar.Minimum = 0;
            zoomTrackBar.Maximum = 17;
            zoomTrackBar.StepFrequency = 1;
    
            // Add Event Handler
            zoomTrackBar.ValueChanged += ZoomTrackBar1_ValueChanged;
    
            // Add items to the right and left panels
            statusBar.RightPaneItems.Add(zoomTrackBar);
            statusBar.RightPaneItems.Add(new RibbonLabel("10%"));
            statusBar.LeftPaneItems.Add(wordcountLabel);
            statusBar.LeftPaneItems.Add(charcountLabel);
    
            // Add Status Bar to the Main Form
            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";
        }
        
    }