< C++ .NET WinForm, Dialog Box & Controls 6 | Main | C++ .NET Drawing 1 >


 

 

Windows Form, Dialog Boxes and More Controls 7

 

 

What we have in this page?

  1. StatusStrip

  2. ToolStripItem Class

  3. StatusStrip Items Collection Editor

  4. StatusStrip Tasks Dialog Box

  5. Using StatusStrip and Status Bars

 

 

 

 

 

 

StatusStrip

 

StatusStrip replaces and extends the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose it. A StatusStrip control displays information about an object being viewed on a Form, the object's components, or contextual information that relates to that object's operation within your application. Typically, a StatusStrip control consists of ToolStripStatusLabel objects, each of which displays text, an icon, or both. The StatusStrip can also contain ToolStripDropDownButton, ToolStripSplitButton, and ToolStripProgressBar controls. The default StatusStrip has no panels. To add panels to a StatusStrip, use the System.Windows.Forms.ToolStripItemCollection.AddRange(System.Windows.Forms.ToolStripItem[]) method. There is extensive support for handling StatusStrip items and common commands in Visual Studio. Important StatusStrip Members are listed in the following Table.

 

Name

Description

CanOverflow

Gets or sets a value indicating whether the StatusStrip supports overflow functionality.

Stretch

Gets or sets a value indicating whether the StatusStrip stretches from end to end in its ToolStripContainer.

 

Table 12

 

The important StatusStrip companion classes include:

 

Name

Description

ToolStripStatusLabel

Represents a panel in a StatusStrip control.

ToolStripDropDownButton

Displays an associated ToolStripDropDown from which the user can select a single item.

ToolStripSplitButton

Represents a two-part control that is a standard button and a drop-down menu.

ToolStripProgressBar

Displays the completion state of a process.

 

Table 13

 

ToolStripStatusLabel replaces and adds functionality to the StatusBar control of previous versions. A ToolStripStatusLabel represents an individual panel of a StatusStrip control. It can contain text or an icon that reflects the status of an application. You can use the ToolStripItemCollection class to find, add, or remove ToolStripStatusLabel objects. Although ToolStripStatusLabel replaces and adds functionality to the StatusBarPanel control of previous versions, StatusBarPanel is retained for both backward compatibility and future use if you choose.

ToolStripItemCollection class represents a collection of ToolStripItem objects. The Add, Remove, and RemoveAt methods enable you to add and remove individual controls from the collection. You can also use the AddRange or Clear methods to add or remove all the controls from the collection. You can determine whether a ToolStripItem is a member of the collection by passing the control into the Contains method. To get the index value of the location of a ToolStripItem in the collection, pass the control into the IndexOf method. The collection can be copied into an array by calling the CopyTo method.

 

ToolStripItem Class

 

ToolStripItem class represents the base class that manages events and layout for all the elements that a ToolStrip or ToolStripDropDown can contain. A ToolStripItem is an element such as a button, combo box, text box, or label that can be contained in a ToolStrip control or a ToolStripDropDown control, which is similar to a Windows context menu. The ToolStrip class manages the painting and keyboard and mouse input, including drag-and-drop input, for these elements, and the ToolStripItem class manages events and layout. The following table shows the elements that derive from the ToolStripItem class and which therefore can be hosted in a ToolStrip or ToolStripDropDown.

 

Element

Description

ToolStripButton

A toolbar button that supports images and text.

ToolStripLabel

A text label typically used in a status bar or ToolStrip as a comment or title.

ToolStripSeparator

A non-selectable space or space with a vertical bar that visually groups elements.

ToolStripControlHost

A ToolStripItem that hosts a ToolStripComboBox, ToolStripTextBox, ToolStripProgressBar, other Windows Forms controls, or custom controls.

A ToolStripComboBox is a text box in which the user can enter text, along with a list from which the user can select text to fill the text box.

A ToolStripTextBox enables the user to enter text.

A ToolStripProgressBar represents a Windows progress bar control contained in a StatusStrip.

ToolStripDropDownItem

A ToolStripItem that hosts a ToolStripMenuItem, ToolStripSplitButton, and ToolStripDropDownButton.

A ToolStripMenuItem is a selectable option displayed on a menu or context menu.

A ToolStripSplitButton is a combination of a regular button and a drop-down button.

A ToolStripDropDownButton is a button that supports drop-down functionality.

ToolStripStatusLabel

A panel in a StatusStrip control.

 

Table 14

 

StatusStrip Items Collection Editor

 

In the previous practices you have encountered Items Collection Editor for many controls. Here, we will try to describe this thing in general. The StatusStrip Items Collection Editor is used to add, remove, and reorder ToolStripItem controls of a StatusStrip and view and set StatusStrip and ToolStripItem properties. Display the StatusStrip Items Collection Editor by:

 

 

Function

Description

Add

Click to add the ToolStripItem that is displayed in the drop-down list. You can add one or more of the following controls:

 

  • ToolStripStatusLabel.

  • ToolStripProgressBar.

  • ToolStripDropDownButton.

  • ToolStripSplitButton.

 

Members

Displays the StatusStrip and the members that it contains.

Properties

Displays the properties of the StatusStrip or a selected member for editing.

Remove

Click the X button to remove the selected ToolStripItem. You cannot use this button to remove the StatusStrip itself.

Reorder

Click the UP and DOWN arrows to move the selected ToolStripItem up or down in the Members list. Changes of order are reflected on the Windows Form in the designer.

 

Table 15

 

StatusStrip Tasks Dialog Box

 

The Tasks Dialog Box also has been used in the previous practices and in other Windows developer tools. Here we provide the general information for control’s Tasks Dialog Box. The StatusStrip Tasks dialog box provides convenient access to typical commands and property settings. Display the StatusStrip Tasks dialog box by clicking the smart tag on a StatusStrip control in the designer.

 

Task

Description

Embed in ToolStripContainer

Click to put the StatusStrip into a ToolStripContainer instead of directly onto the form.

RenderMode

Select System, Professional, or ManagerRenderMode as the ToolStripRenderMode for the control.

Dock

Provides options that specify which borders of the control are bound to its container.

Edit Items

Displays the StatusStrip Items Collection Editor, from which you can add, remove, and reorder items, and set properties.

 

Table 16

 

Using StatusStrip and Status Bars

 

The StatusStrip class represents the standard status bar that you see at the bottom of many application windows. As its name implies, the purpose of a status bar is to present status information to the user. Simple status bars display one or more text items, and if you want a more advanced display, you can take over part or all of the drawing of the status bar to display bitmaps, progress controls, or other UI elements. Because this module is presenting an introduction to controls, we will concentrate on showing you how to display text on a status bar. Although you can add a status bar to any form, they’re not usually added to dialog boxes. The following exercise shows how to add a status bar to a form and how to use the status bar to display information.

 

48.     Drag a StatusStrip from the Toolbox onto the form. As with the ToolStripContainer, you’ll find that it doesn’t stretch right across the bottom of the form.

 

Adding StatusStrip control to the existing WinForm for displaying status bar

 

49.     From the StatusStrip Tasks dialog select Embed in ToolStripContainer.

 

Embedding StatusStrip in the ToolStripContainer

 

50.     Next, from the ToolStripContainer Tasks, tick the Bottom and select Dock Fill in Form.

 

Docking the StatusStrip control to the bottom of the Form

 

Docking the StatusStrip to fill the bottom of the form

 

51.     Then from the ToolStripContainer Tasks, select Re-parent Controls.

 

Re-parent StatusStrip control

 

52.     Change the RenderMode property to Professional.

 

Changing the RenderMode property of the StatusStrip to Professional

 

53. Next, let add a StatusLabel to the StatusStrip. Select the Edit Items… from the StatusStrip Tasks dialog to invoke the Items Collection Editor (You can also add StatusLabel and other controls directly from the shortcut in the StatusStrip). Select StatusLabel from the ComboBox and click the Add button.

 

Adding StatusLabel to th StatusStrip

 

54. Select toolStripStatusLabel1, expand the Font property and set the Bold property to True. Set the BackColor to ActiveCaptionText and click the OK button.

 

Setting toolStripStatusLabel1 properties using Items Collection Editor

 

  StatusStrip with one StripSatusLabel

 

55. Now we are ready to add code for our StripStatusLabel. You can easily use the StripStatusLabel to display the path whose contents are currently being listed in the ListView. To do so, add a line to the start of the Fill_ListView function, like this:

// Put the path in the status bar

toolStripStatusLabel1->Text = path;

 

Adding code for displaying path in the status bar

 

56.     Build and run your project. Select any folder in the TreeView and you can see the path shown in the status bar.

 

Windows explorer Form with status bar feature in action

 

A StatusStrip can display a sizing grip to the lower right, which allows users to resize the window. The sizing grip is displayed by default, but you can turn it off by setting the SizingGrip property to false.

 

Setting the SizingGrip property to false

 

You might notice that the path displayed has two backslashes as the first separator. These appear because the root directory name is returned as C:\, and when the TreeView builds the full path for you, it uses a backslash as the path separator. Having two backslashes instead of one makes no difference to using the path, but if you want to tidy up the path, you can easily remove one from the root name. You can display more than one piece of information on a status bar, as shown here:

 

Status bar with several labels in Windows explorer

 

Each of the sunken areas on the status bar is called a panel, and you can add as many panels as you want to the StatusStrip by adding the more StripStatusLabel. If you play around with the property of the StripStatusLabel and other controls you can generate a very nice and informative status bar that include launching dialog box, buttons, image and URL, normally found in the commercial applications. The following figures show a very simple creativity.

 

Setting properties for more than one ToolStripLabels

 

Our Windows Explorer version in action!!!!!

 

 

 

 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

 


 

< C++ .NET WinForm, Dialog Box & Controls 6 | Main | C++ .NET Drawing 1 >