Events in Images application
The Image application responds to the event as follows:
1. The Click event of each Image control makes the Left property of the Shape control the same as its own Left property and moves the graphic to the top of the Image.
2. Call the Cls method of PictureBox to clear the current title of StatusBar.
3. Call the PRint method of PictureBox to print the new title on the StatusBar.
The code for the Click event of the Image control is as follows:
PrivateSubimgHeart_Click()
shpCard.Left=imgClub.LeftpicStatus.Cls
picStatus.PrintSelected:Club
shpCard.Visible=True
EndSub
Note that the first line of the Click event code uses the = operator to assign a value to the Left property of the Shape control (making it equal to the Left property of the Image control). The next two lines call methods, so no operators are needed. In the third line, the value (Selected:Club) is a parameter of the Print method.
There is one more line of code in the application that is important; it's in the FormLoad event.
shpCard.Visible=False
Set the Visible property of the Shape control to False, and the Shape control is hidden until the first Image is clicked.
Set the Visible property to True in the last step of the Image control's Click event.
For more information about properties, methods, and events, see Chapter 5, "Programming Fundamentals."
Additional controls
The Visual Basic toolbox also contains several other standard controls. There are controls that can be used to process large amounts of data in external databases. There are controls available for accessing Windows file systems. There are other controls that are difficult to classify but are very useful.
ActiveX controls, formerly known as custom controls or OLE controls, can also be used in Visual Basic applications and can be used in the same way as standard controls. Several ActiveX events in the Professional and Enterprise editions of Visual Basic also have the ability to create custom controls. As you can imagine, with the addition of a large number of additional ActiveX controls produced by manufacturers, almost any task can be completed.
Detailed information For detailed information about using ActiveX controls, please refer to Chapter 4 "Project Management".
data access control
In modern business, most information is stored in one or more central databases. VisualBasic provides a variety of data access controls that can access most popular databases, such as Microsoft Access and SQL Server.
1.ADOData control is used to connect to the database. Think of it as a pipeline between the database and other controls in the form. The Data control's properties, methods, and events allow external data to be located and manipulated from within the application.
2. The DataList control is similar to the ListBox control. When the DataList control is used with the ADOData control, it will automatically be populated with a data list from a field in the external database.
3. The DataCombo control is like a combination of DBList and TextBox. Selected text within the TextBox area can be edited, and changes appear in the underlying database.
4.The DataGrid control displays data in a grid or table. When used with the ADOData control, it displays fully editable data from multiple fields in an external database.
5.The MicrosoftHierarchicalFlexGrid control is the only control that can display multiple views of data. Think of it as a combination of a grid and a tree or outline control. At runtime, users can rearrange rows and columns to provide different views of the data.
For more information about the Data control, see Chapter 7, "Using Visual Basic's Standard Controls."
file system control
Visual Basic provides three controls to increase file handling capabilities in your application. Typically, these controls are used together to view drives, directories, and files. There are special properties and events that connect them to each other.
The DriveListBox control looks like a ComboBox. It provides a drop-down list of drives from which the user can make a selection.
DirListBox is similar to the ListBox control, but it has the built-in ability to display a listing of the directory on the currently selected drive.
The FileListBox control looks like a ListBox that displays a list of file names for a selected directory.
Note that these controls are provided primarily for backward compatibility with applications created in earlier versions of Visual Basic. The CommonDialog control provides a simple way to handle file access. For more information about the CommonDialog control, see "Other Controls" later in this chapter.
Other controls
VisualBasic also provides several other standard controls. Each control serves a unique purpose.
The Timer control can generate an event at recurring intervals in your application. This is useful for the execution of code that does not require user interaction.
OLE container controls make it easy to add functions such as linking and embedding to applications. Through the OLE container control, you can provide access to the functionality of any OLE-available application (such as Microsoft Excel, Word, and many other applications).
The CommonDialog control adds built-in dialog boxes to applications for selecting files, colors, fonts, and printing functions.
Details For additional information about standard controls, see Chapter 7, "Using Visual Basic's Standard Controls."
Focus overview
The focus is on the ability to receive user mouse or keyboard input. When an object has focus, it can receive input from the user. In the Microsoft Windows interface, several applications can be running at any time, but only the application with focus has an active title bar and can accept user input. In a Visual Basic form with several TextBoxes, only the TextBox with focus displays text entered by the keyboard.
When an object gains or loses focus, the GotFocus or LostFocus event is generated. Forms and most controls support these events.
The following methods assign focus to an object.
Select objects at runtime.
Use shortcut keys to select objects at runtime.
Use the SetFocus method in your code.
For some objects, it can be seen whether it has focus. For example, when a command button has focus, the border around the title is highlighted (see Figure 3.19).
An object can receive focus only if its Enabled and Visible properties are True. The Enabled property allows the object to respond to user-generated events, such as keyboard and mouse events. The Visible property determines whether the object is visible on the screen.
Note that only a form that does not contain any controls that can receive focus can receive focus.
Validate event of the control
The control also has a Validate event, which occurs before the control loses focus. However, this event occurs only when the CausesValidation property of the control about to receive focus is set to True. In many cases, because the Validate event occurs before losing focus, it is more suitable for data validation than the LostFocus event. For more information, see "Validating Control Data by Restricting Focus" in Chapter 7, "Using Visual Basic Standard Controls."
Controls that cannot accept focus
Some controls, such as lightweight controls, cannot accept focus. Lightweight controls include the following controls:
Frame control
Image control
Label control
Line control
Shape control
In addition, controls that are not visible at run time, such as the Timer control, cannot accept focus.
->