How to Use Advanced Windows Forms | 2 | WebReference

How to Use Advanced Windows Forms | 2

How to Use Advanced Windows Forms

18.1.3 Explorer interfaces

In an explorer interface a hierarchy or other organization is imposed on a concept or set of concepts, with the hierarchy shown on one side and details related to a selected item shown in the main portion of the window. The classic example of this style is the Windows Explorer interface, which displays information about the data available on the computer, be it from disk, CD, network, or another source.

Explorer interfaces give an overview of the concept in question, and typically provide a tree control to allow the user to explorer the data at a high level or successive levels of detail. The user can select a specific item, or node, in the tree and see information about this item in the other portion of the interface, most commonly in the form of a list showing the selected item's contents.

In this chapter we start building the MyAlbumExplorer interface as an example of this style. The end result is shown in figure 18.3. The next section begins this discussion with an exploration of splitter controls and an introduction to the TreeView and ListView controls.

18.2 EXPLORER INTERFACES IN .NET

Now that we've reviewed the three main interface styles for Windows applications, let's take a look at the explorer interface in more detail. Part 1 of the book built a single document interface, and we examine multiple document interfaces in chapter 20. We discuss the explorer interface style in this as well as the next chapter. This chapter focuses more on the interface itself, and the tree view and splitter controls commonly used for this interface. Chapter 19 elaborates on this discussion and examines the ListView control.

While building an explorer interface has always been possible in .NET, the release of .NET 2.0 made this task much easier. In the .NET 1.x releases, a Splitter class was provided that split a container into two distinct regions. The proper location of the splitter object was dependent on the order in which controls were added to the container, which could get rather confusing. This class is still available in .NET 2.0, but Microsoft no longer recommends its use.

Recognizing the error of their ways, the Windows Forms team has added the SplitContainer control. This class works much like the JSplitPane class in the Java Swing interface, for you Java aficionados out there. We discuss split containers in a moment.

Once a SplitContainer object is on a form, a TreeView control can be dropped into the left-hand side and a ListView control into the right-hand side. Explorer interfaces in Windows were never quite so easy.

We begin our discussion with the splitter controls.

18.2.1 The SplitContainer class

As already indicated, the SplitContainer class is the recommended mechanism for splitting a container into multiple sections. The members of this class are shown in .NET Table 18.1. As you can see, the SplitContainer class provides a number of properties to control the appearance of the two resulting panels. The size of each panel can be adjustable or fixed, depending on the FixedPanel and IsSplitter- Fixed properties described in the table. Panel-specific properties define a minimum size for each panel and allow either panel to be hidden from view.

The movable bar within a split container, called the splitter, is affected by properties that define its location and size within the container. The SplitterIncrementproperty allows a splitter to move in increments larger than one pixel. Additional tasks can be performed before or after a user moves the splitter by handling the SplitterMoved and SplitterMoving events.

Split containers can orient their panels in the horizontal or vertical direction, and can be nested to allow multiple display areas within a form. A quick example of these two concepts appears in listing 18.1, which creates the form shown in figure 18.4. This example displays a horizontal split container nested within the right panel of a vertical split container. Each panel assigns a different BackColor setting so the location of each splitter panel is immediately apparent.

 

Created: March 27, 2003
Revised: May 1, 2006

URL: https://webreference.com/programming/winforms/1