home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
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

Search this book:
 
Previous Table of Contents Next


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 user’s point of view. It describes the control’s run time user interface, and it explains the ways the user can interact with the control.

The section “Programming Bar Gauge” details the control’s features from an application developer’s 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 gauge’s 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 control’s 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 control’s 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:
appears2D—Flat, two-dimensional
borders
appears3D—Three-dimensional
borders
BackColor OLE_COLOR The gauge’s 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 gauge’s minimum value
Max Long The gauge’s maximum value
Value Long The gauge’s current value
KeyChangeAmount Long The amount Value changes when the user presses an arrow key
Style GaugeStyle This enumerated type can have the values:
gsLeftToRight—Horizontal withMax on the rightgs
RightToLeft—Horizontal with
Max on the left
gsBottomToTop—Vertical with Max
on the topg
sTopToBottom—Vertical 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 control’s 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 control’s properties are handled quite differently than those used by the alarm control. This section describes the bar gauge’s new properties.
•  Drawing Bar Gauge. Most of the bar gauge’s properties affect the control’s 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 gauge’s 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 control’s 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.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.