A Revamped User Interface
The official style of Windows applications has never been determined by the official APIthe Windows SDK earlier and the .NET Framework now. Flagship applications like Microsoft Office and Visual Studio have always boasted the user interface of tomorrow's user applications and gave the start to a bunch of third-party companies to provide similar controls to the community.
|Figure 7: The new ToolStrip control at design-time.|
In the .NET Framework 2.0, Microsoft has updated some user interface controls including toolbars and menus to look much more trendy and appealing to users. Any Windows Forms 2.0 applications can now show the same look-and-feel of Microsoft Office 2003 or Visual Studio 2005.
The new MenuStrip and ToolStrip controls are the successors to MainMenu and Toolbar respectively, but they provide all the features of popular applications including rebar bands, gradients of color, and a variety of different items. Figure 7 shows a ToolStrip control at design-time.
As you can guess from the figure, the control is a collection of items each with a different user interface and capabilities. Feasible items include buttons, labels, separators, drop-down lists, drop-down buttons, text boxes, and progress bars. You build your toolbar by taking advantage of the rich services offered by Visual Studio 2005 and arranging any combination of the above items.
You can associate each button with a bitmap; but where do you store these images? You should take these bitmaps out of a resource file possibly embedded in the assembly. In Windows Forms 1.x, though, working with resources was no picnic. Things are much better in Visual Studio 2005. Figure 8
shows the dialog box you use to configure a toolbar button.
You can easily control the behavior of the button and decide whether it is enabled or disabled, if it has to show a shortcut key, or toggle its pressed state on click. Likewise, you can control text, name, type, and image. When you click to edit the image, a new dialog box appears to let you import images from your hard drive into a brand new resource file. Needless to say, Visual Studio 2005 automatically creates the resource .resx file and attaches it to the current project. As a result, from now on your images travel with your assemblies.
In Windows Forms 2.0, you will find two classes for each type of menu you may think ofmain menu and context menu. MenuStrip and ContextMenuStrip are new to the .NET Framework 2.0 and provide a nicer user interface and a richer set of design-time services. You'll also find the menu classes you know from the previous version of the .NET Framework. These classes haven't been updated. Note, though, that in order to associate a context menu to a .NET control, you have to define a ContextMenuStrip object. Figure 9 demonstrates the new look-and-feel of menus.
|Figure 9: The new user interface of Windows menus.|
Speaking of strip controls, the StatusStrip control is also worth mentioning. It succeeds the Status Bar control and is rendered as a collection of rich items like text panels (the standard cells of classic status bars), progress bars, drop-down lists, and split buttons. (A split button is a variant of a drop-down list like the "People" button in the toolbar of Figure 9
HTML-based user interfaces give you much more freedom when it comes to designing the layout of a form. This <table> tag provides most of the flexibility because its usage goes far beyond the original goal of providing a tabular list of strings.
While building HTML pages, you place one or more <table> tags in a page and populate each cell with any combination of tags and text. Windows forms don't have an equivalent to the <table> tag. This doesn't mean, though, that you can't get the same flexibility when you build a user interface in a Windows application; quite the reverse, I'd say. The rub, though, is that you have to build it yourself, step-by-step, and with no help from the designer.
In Windows Forms 2.0, you will find the TableLayoutPanel and FlowLayoutPanel layout controls that help a lot in pursuing a behavior similar to the <table> tag of HTML pages.
|Figure 10: A TableLayoutPanel control in action at design time.|
The TableLayoutPanel represents a panel that dynamically lays out its content in a grid composed of a given number of rows and columns. The FlowLayoutPanel dynamically lays out its contents horizontally or vertically. Each cell of the grid (see Figure 10
) contains at most one control. If you need to display more controls, you should first create a composite custom control to group them all with any needed glue code.
Both controls inherit from Panel and implement the IExtenderProvider interface to automatically extend the programming interface of contained controls. Dynamically added properties include Row, RowSpan, Column, and ColumnSpan. The TableLayoutPanel supports a fair number of visual properties much like the HTML counterpart.