Learn Visual Basic 6.0
10. Other Visual Basic Topics
Review and Preview
In this last class, we look at a lot of relatively unrelated topics - a Visual Basic playground. We'll cover lots of things, each with enough detail to allow you, as a now-experienced Visual Basic programmer, to learn more about the topics that interest you.
Custom Controls
A custom control is an extension to the standard Visual Basic toolbox. You use custom controls just as you would any other control. In fact, you've used (or at least seen) custom controls before. The common dialog box, the DBList box, the DBCombo box, and the DBGrid tool, are all examples of custom controls. Custom controls can be used to add some really cool features to your applications.
Custom controls are also referred to as ActiveX controls. ActiveX is a technology newly introduced by Microsoft to describe what used to be known as OLE Automation. Prior to Visual Basic 5.0, the only way to create your own controls was to use C or C++. Now, with ActiveX technology, you can create your own controls knowing only Visual Basic! Of course, this would be a course by itself (and is).
To use a custom control, you must load it into the toolbox. To do this, choose Components from the Visual Basic Project menu. The Components (custom controls) dialog box is displayed.
To add a control, select the check box next to the desired selection. When done, choose OK and the selected controls will now appear in the toolbox.
Each custom control has its own set of properties, events, and methods. The best reference for each control is the Microsoft Visual Basic Component Tools Guide manual that comes with Visual Basic 6.0. And, each tool also features on-line help.
Here, we'll look at several custom controls and brief examples of their usage. And, we'll give some of the more important and unique properties, events, and methods for each. The main purpose here is to expose you to a few of these controls. You are encouraged to delve into the toolbox and look at all the tools and find ones you can use in your applications.
Masked Edit Control
The masked edit control is used to prompt users for data input using a mask pattern. The mask allows you to specify exactly the desired input format. With a mask, the control acts like a standard text box. This control is loaded by selecting the Microsoft Masked Edit Control from the Components dialog box.
Possible uses for this control include:
To prompt for a date, a time, number, or currency value.
To prompt for something that follows a pattern, like a phone number or social security number.
To format the display and printing of mask input data.
Masked Edit Properties:
Mask Determines the type of information that is input into the control. It uses characters to define the type of input (see on-line help for complete descriptions).
Text Contains data entered into the control (including all prompt characters of the input mask).
Masked Edit Events:
Change Event called when the data in the control changes.
Validation Error Event called when the data being entered by the user does not match the input mask.
Masked Edit Example:
We'll use the masked edit control to obtain a phone number. Place a masked edit control on a form. Set the masked edit controls Mask property equal to:
(###)-###-####
Set the Font Size property to 12. My form now looks like this:
Run the example and notice how simple it is to fill in the phone number. Break the application and examine the Text property of the control in the Immediate Window.
Chart Control
Wyszukiwarka