8.23 Adding StatusBar Panels to Display Application State

 <  Day Day Up  >  

8.23 Adding StatusBar Panels to Display Application State

You want to create various status bar panels at the bottom of your application's form to display application information.


Technique

Using the form designer toolbox, drag a StatusBar control and drop it onto your Windows Form. A StatusBar can contain zero or more panels, each of which contain a Text property to display text in the panel. The following code uses a StatusBar object with a single panel to display information to the user when the mouse moves over a toolbar button. Using the MouseMove event, you find the corresponding toolbar button by computing the index of the toolbar button using the current location of the mouse cursor. If the mouse cursor is over a toolbar button, the button's tooltip property is accessed and its text is used as the value to the StatusBar control's Text property:

 
 private void toolBar1_MouseMove(object sender,     System.Windows.Forms.MouseEventArgs e) {     // determine button based on mouse coords and width of buttons     int buttonIndex = e.X/toolBar1.ButtonSize.Width;     if( buttonIndex > toolBar1.Buttons.Count - 1 )     {         statusMessage.Text = "";     }     else     {         statusMessage.Text = toolBar1.Buttons[buttonIndex].ToolTipText;     } } 

Comments

A status bar is a useful control that allows a user to quickly retrieve information about the state of the application without any form of interaction necessary. For instance, while working with code in the Visual Studio .NET IDE, you always know the row, column, and character where the text cursor is currently located by looking at the corresponding information in the status bar at the bottom of the IDE window.

The status bar can contain any number of panels used to separate the information it displays. Some of the common groupings include cursor location information, document information such as number of pages, and key state information such as the state of the CapsLock or Insert keys.

The StatusBar control uses the Panel collection to create additional panels for display. Each of these panels contains a Text property to display an informational message and an optional icon on the left of the message defined in the StatusBarPanel Icon property, as shown in Figure 8.8.

Figure 8.8. The StatusBar control can contain a text message with an optional leading icon.

graphics/08fig08.gif

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net