Properties, methods and Events of VB (v)

Source: Internet
Author: User
Tags contains file system ole

Images events in an application

The image application responds to events as follows:
1. The Click event for each image control causes the left property of the shape control to be the same as its own leave property and moves the graphic to the top of the image.
2. Call the PictureBox Cls method to clear the current caption of the StatusBar.
3. Call PictureBox's Print method to print the new caption on the StatusBar.
The code for the Image control Click event is as follows:
Private Sub Imgheart_click ()
Shpcard.left = ImgClub.LeftpicStatus.Cls
Picstatus.print "Selected:club"
Shpcard.visible = True
End Sub
Notice that the first line in the Click event code assigns a value to the left property of the Shape control using the = operator (to make it equal to the left-hand property of the image control). The following two lines call the method, so no operator is required. In the third row, the value ("Selected:club") is a parameter of the Print method.
It is important to have one row in the application code, which is in the Form Load event.
Shpcard.visible = False
Set the Visible property of the Shape control to the False,shape control to hide until you click the first image.
Set the Visible property to true in the last step of the image control Click event.
For more information about properties, methods, and events, see Chapter Fifth, "Programming basics."

Additional controls
The Visual Basic Toolbox also contains several other standard controls. Some controls can be used to handle large amounts of data in an external database. Some controls can be used to access the Windows file system. There are other controls that are difficult to categorize, but useful.
You can also use ActiveX controls in Visual Basic applications, formerly known as custom controls or OLE controls, in the same way as using standard controls. Several ActiveX events in Visual Basic Professional and Enterprise editions also have the ability to create custom controls. As you can imagine, adding ActiveX controls made by a large number of vendors can do almost any job.
For more information about using ActiveX controls, see Chapter Fourth "Management of Works".

Data access Control
In modern business, most of the information is stored in one or more central databases. Visual Basic provides a variety of data access controls that can access most popular databases, such as Microsoft access and SQL servers.
The 1.ADO data control is used to connect to the database. You can think of it as a pipe line between a database and another control in a form. The properties, methods, and events of the data control allow the external data to be positioned and processed from within the application.
The 2.DataList control is similar to the ListBox control. When used with an ADO data control, the DataList control is automatically populated with a list of fields from an external database.
A 3.DataCombo control is like a combination of dblist and a TextBox. The text selected in the TextBox area can be edited and the changes appear in the underlying database.
A 4.DataGrid control displays data in a grid or table. When used with the ADO Data control, it displays fully editable data from multiple fields in the external database.
The 5.Microsoft Hierarchical FlexGrid control is the only control that can display multiple views of data. You can think of it as a combination of a grid and a tree or a master control. At run time, users can reschedule rows and columns to provide different views of the data.
For more information about the Data control, see Chapter Seventh "Standard controls with Visual Basic."

File system controls
Visual Basic provides three controls to increase the ability to handle files in your application. Typically, these controls are used together to view drives, directories, and files. There are special properties and events that make them interconnected.
The DriveListBox control looks like a ComboBox. It provides a drop-down list of drives from which the user can make a choice.
DirListBox is similar to a ListBox control, but it has built-in capabilities to display a list of currently selected drive directories.
The FileListBox control looks like a ListBox that displays a list of file names for the selected directory.
Note These controls are primarily provided for the backward compatibility of 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 "Additional Controls" later in this chapter.

Other controls
Visual Basic also provides several other standard controls. Each control serves a unique purpose.
The Timer control can generate an event at a repeating interval in the application. This is useful for the execution of code that does not require interaction with the user.
OLE container controls can easily add functionality such as linking and embedding to your application. With OLE container controls, you can provide access to the functionality of any ole--available applications, such as Microsoft Excel, Word, and many other applications.
The CommonDialog control adds a built-in dialog box to the application to select files, colors, fonts, and print functions.
For additional information about standard controls, see Chapter Seventh "Standard controls with Visual Basic."

Focus Overview
The focus is 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, you can run several applications at any one time, but only the application with focus has the active title bar to accept user input. In a Visual Basic form with several textbox, only the TextBox with focus displays the text entered by the keyboard.
GotFocus or LostFocus events occur when the object gets or loses focus. Forms and most controls support these events.

The following methods can assign focus to an object.
Select the object at run time.
Use shortcut keys to select objects at run time.
Use the SetFocus method in your code.
Some objects, whether or not it has the focus, can be seen. For example, when a command button has focus, the border around the caption is highlighted (see Figure 3.19).
It receives the focus only if the Enabled and Visible properties of the object are True. The Enabled property allows an object to respond to events generated by the user, such as keyboard and mouse events. The Visible property determines whether the object is visible on the screen.

Note that only the form that does not contain any control that can receive the focus can receive the focus.

Validate Events for controls
Control also has a validate event that occurs before the control loses focus. However, this event occurs only when the CausesValidation property of the control that receives the focus is set to true immediately. In many cases, because the Validate event occurs before the focus is lost, it is more appropriate for data validation than for LostFocus events. For more information, see "Validating control data by limiting focus" in chapter seventh, "Using Visual Basic Standard Controls".

Controls that cannot accept focus
Some controls, such as lightweight controls, cannot accept focus. The lightweight control contains the following controls:
Frame control
Image control
Label control
Line control
Shape Control
In addition, a control that is not visible at run time, such as a timer control, cannot accept focus.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.