|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97
Chapter 15 Bar Gauge
The ActiveX alarm control described in Chapter 14 works behind the scenes with a client application rather than interacting directly with the end user. This control is fairly extreme in the sense that it has no user interface at run time. At the other extreme, the bar gauge control has a rich user interface. It is designed to interact directly with the end user while displaying and modifying data values.
The first section in this chapter, Interacting with Bar Gauge, explains how the control works from the end users point of view. It describes the controls run time user interface, and it explains the ways the user can interact with the control.
The section Programming Bar Gauge details the controls features from an application developers point of view. It describes the properties and events an application can use to manage the control.
The Key Techniques section briefly lists the main tasks the ActiveX control must handle to support both the application developer at design time and the end user at run time. The rest of this chapter describes the bar gauges internals and explains how the control handles these tasks.
Interacting with Bar Gauge
The bar gauge control displays a value by showing an area partially covered with a foreground color. This is similar to the way a thermometer shows the temperature by covering part of its scale with mercury or some other liquid.
When the bar gauge is enabled, the user can click and drag on it to set a new value. When the control has the input focus, it displays a dotted border and the user can modify the controls value using the arrow keys. The up and down arrow keys affect vertical gauges, and the left and right arrow keys affect horizontal gauges.
The example program group BarGauge.VBG in the Ch15\BarGauge directory demonstrates the bar gauge control. It creates four gauges, two horizontal and two vertical. When the user changes the value of a gauge, the program updates the label next to that gauge to show the new value. Figure 15.1 shows the running BarGauge program. The vertical gauge on the right displays the dotted border indicating that it has the input focus.
FIGURE 15.1 The BarGauge application.
Programming Bar Gauge
The bar gauge control supports several standard properties as well as a few that are customized for its own needs. The standard properties are listed in Table 15.1. They behave exactly as they do for other controls. The controls customized properties are listed in Table 15.2.
| Table 15.1 Standard Bar Gauge Properties
|
| Property
| Type
| Meaning
|
| Appearance
| AppearanceValue
| This enumerated type can havethe values: appears2DFlat, two-dimensional borders appears3DThree-dimensional borders
|
| BackColor
| OLE_COLOR
| The gauges background color
|
| ForeColor
| OLE_COLOR
| The color displayed to represent the value (the mercury in athermometer)
|
| TabStop
| Boolean
| Determines whether the tab key stops at the control
|
| Enabled
| Boolean
| Determines whether the user can interact with the control
|
|
| Table 15.2 Customized Bar Gauge Properties
|
| Property
| Type
| Meaning
|
| Min
| Long
| The gauges minimum value
|
| Max
| Long
| The gauges maximum value
|
| Value
| Long
| The gauges current value
|
| KeyChangeAmount
| Long
| The amount Value changes when the user presses an arrow key
|
| Style
| GaugeStyle
| This enumerated type can have the values:
|
|
|
| gsLeftToRightHorizontal withMax on the rightgs RightToLeftHorizontal with Max on the left gsBottomToTopVertical with Max on the topg sTopToBottomVertical with Max on the bottom
|
|
In some ways this control is similar to the scroll bars provided by Visual Basic. The Min and Max properties determine the range of values represented by the control. The Value property determines its current value. The KeyChangeAmount property indicates the amount by which the Value is modified in response to arrow keys.
Key Techniques
The bar gauge control implements the same standard subroutines required by the alarm control described in Chapter 14 so they are not described here. These include the InitProperties, WriteProperties, and ReadProperties event handlers needed to manage an ActiveX controls properties.
The bar gauge also provides new user interaction capabilities not provided by the alarm control. The following list briefly describes those features. The rest of the chapter explains how they are implemented in detail.
- Managing Bar Gauge Properties. Because the bar gauge has a visible interface, many of this controls properties are handled quite differently than those used by the alarm control. This section describes the bar gauges new properties.
- Drawing Bar Gauge. Most of the bar gauges properties affect the controls appearance. This section explains how the control redraws itself when property values change.
- Managing the Mouse. Because the mouse is used to select a bar gauges value, mouse events play a critical role in the bar gauge control. This section tells how the control reacts to mouse movements.
- Handling Keyboard Events. To make itself easier to use, the bar gauge allows the user to change the controls value using the arrow keys. This section explains how the bar gauge handles keyboard events.
- Modifying Bar Gauge. The bar gauge control demonstrates how an ActiveX control can handle mouse and keyboard events. This section describes slight modifications that create other gauges with very different appearances.
|