Sunday, 8 May 2011

Status Bar Control in C#

StatusBar Control
         A status bar is commonly used to provide hints for the selected item or information about an action currently being performed on a dialog. Normally, the StatusBar is placed at the bottom of the screen, as it is in MS Office applications and Paint, but it can be located anywhere you like.
StatusBar Properties
Name
Availability
Description
BackgroundImage Read/Write It is possible to assign an image to the status bar that will be drawn in the background.
Panels Read-only This is the collection of panels in the status bar. Use this collection to add and remove panels.
ShowPanels Read/Write If you want to display panels, this property must be set to true.
Text Read/Write When you are not using panels this property holds the text that is displayed in the status bar.
StatusBar Events
Name
Description
DrawItem Occurs when a panel that has the OwnerDraw style set needs to be redrawn. You must subscribe to this event if you want to draw the contents of a panel yourself.
PanelClick Occurs when a panels is clicked.
The StatusBarPanel Class
This class contains all the information about the individual panels in the Panels collection. The information that can be set ranges from simple text and alignment of text to icons to be displayed and the style of the panel.
Example  For StatusBar
To understanding StatusBar control drag and drop status strip and make text blank and add 2toolstatuslabel and 1 toolstatusprogressbar. And drag 1textbox and 1 button,1timer control and change property according to your choice.
                                  
Code for button click on go button-

private void button1_Click_1(object sender, EventArgs e)
        {
            toolStripProgressBar1.Visible = true;
            toolStripStatusLabel2.Text = "";
            timer1.Enabled = true;
            webBrowser1.Navigate(textBox1.Text);
            toolStripStatusLabel1.Text = textBox1.Text;
        }
                                   
On clicking button progress bar will show on status strip control until webpage will not open. when web page is loaded progress bar will not be display and label text will be web address and done that means page has been loaded as shown below
                                   
Code for timer Control

private void timer1_Tick(object sender, EventArgs e)
        {
           
            toolStripProgressBar1.Value = toolStripProgressBar1.Value + 10;
            
            if (toolStripProgressBar1.Value == toolStripProgressBar1.Maximum)
            {
               
                toolStripProgressBar1.Value= 0;
                toolStripProgressBar1.Visible = false;
                timer1.Enabled = false;
                toolStripStatusLabel2.Text = "Done";             
            }
            
        }
Write following code on document complete event of WebbrowserControl so that progressbar stops
 


private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            toolStripProgressBar1.Visible = false;
        }

1 comment: