Introduction to VB Controls

Source: Internet
Author: User
Tags numeric value versions

Introduction to Visual Basic controls

You can use tools in the Visual Basic Toolbox to draw controls on a form.

Control classification
There are three broad categories of Visual basic controls:
1. Internal controls, such as CommandButton and frame controls. These controls are in the VisualBasic. exe file. Internal controls always appear in the toolbox, not as ActiveX controls and pluggable objects can be added to the toolbox or removed from the toolbox.
2.ActiveX control, a stand-alone file with an. ocx extension, including controls provided by various versions of VisualBasic (DataCombo, DataList controls, and so on) and controls provided only in professional and Enterprise editions (such as ListView, Toolbar , animation and Tabbeddialog), and many other ActiveX controls provided by third parties.
Note Controls with the file name extension. VBX use old technology and can be found in applications written in earlier versions of Visual Basic. When Visual Basic opens a project that contains a. VBX control, it replaces the. VBX control by default with the. OCX control, which, of course, is only available if the control's. ocx version exists. For information about updating controls to. ocx format, see the "Updating Legacy VisualBasic Controls" section later in this chapter.
3. An object that can be inserted, such as a Microsoft Excel worksheet object that contains a list of all employees of the company, or a Microsoft Project calendar object that contains information about a project plan. Because these objects can be added to the toolbox, they can be used as controls. Some of these objects also support automation (the formal name is OLE Automation), which allows you to programmatically control the objects of another application in a Visual Basic application. For more information about automation, see "Programming with Objects" in chapter tenth, "Programming with parts."
For more information about the ActiveX controls that are available in Visual Basic Professional and Enterprise editions, see "Using ActiveX Controls" in the part tools guide.

Internal controls
The following table summarizes the internal controls in the Visual Basic Toolbox.

Note the Pointer tool (the first tool in the toolbox) can be used to move forms and controls, and resize them. The Pointer tool is not a control.

Standard ActiveX controls
The Visual Basic Learning Edition contains several ActiveX controls, called Standard ActiveX controls, with which you can introduce advanced functionality in your application. The ActiveX control's file name extension is. ocx, which can be manually added to the toolbox to use AQ in the project. The following table summarizes the standard ActiveX controls provided by the Visual Basic Learning Edition.

For more information about the ActiveX controls that are available in Visual Basic Professional and Enterprise editions, see "Using ActiveX Controls" in the part tools guide.

Adding and removing ActiveX controls
Follow the steps below to add or remove ActiveX controls in the Toolbox.
To add an ActiveX control to the Toolbox:
1. Select parts from the Project menu.
2. Select the check box next to the name of the. OCX control and choose OK. After you put the controls in the Toolbox, you add them to the form just as you would an internal control.
To delete an ActiveX control:
1. Deletes all instances of the control on the project's form. Deletes all references to the control in the project code. If a reference to the deleted control is still left in the code, an error message is displayed when the application is compiled.
2. Select parts from the Project menu. Clear the check box next to the. OCX control name, and then select OK. If there are instances of controls in the project, an error message is displayed.
For more information about adding or removing controls and pluggable objects in the toolbox, see Chapter Fourth, "Adding controls to Engineering" in "Project management."

Updating legacy Visual Basic controls
16-bit legacy Visual Basic controls with a file extension of. VBX are not compatible with this version of Visual Basic. If you try to load an old project that contains a. VBX control, Visual Basic warns that the control is not applicable or incompatible, and you can continue to load the project without the. VBX control, and of course the application will not function correctly.
If you have an older version of Visual Basic that contains a third-party. VBX control, consult your control manufacturer for information about the. ocx override control.

Control naming conventions
When you create an object (form or control) for the first time, Visual Basic sets its Name property to the default value. For example, initially set the Name property of all command buttons to CommandN, where n is 1, 2, 3, and so on. Visual Basic names The first command button drawn on the form as Command1, the second is Command2, and the third is Command3.
You can leave the default name, but if you have several controls of the same type, it's a good idea to change the Name property to a descriptive name. Naming conventions are useful because it is difficult to distinguish between the Command1 button of the MyForm form and the Command1 button of the yourform, especially when the application contains several forms, standards, and class modules.
You can name the control by using a prefix to describe the class, followed by a descriptive name for the control. With naming conventions, the code automatically describes itself and causes similar objects to be sorted alphabetically in the Object list box. For example, you can name a CheckBox control like this:
Chkreadonly
Names that are named for forms and controls:
1. Must begin with a letter.
2. Only letters, numbers, and underscore characters (_) can be included, and punctuation characters and spaces are not allowed.
3. No more than 40 characters.
For more information about naming conventions, see Appendix B, "Visual Basic coding conventions."

Using control values
All controls have a property that simply refers to the control name without using the property name to store or get a numeric value, which is called the value of the control, which is the most important or most common property of the control. The following table lists each control property, which is considered a control value.

When a control's property is the value of the control, you do not have to specify the property name in your code whenever you reference this property. For example, the downlink code sets the Text property value for a TextBox control:
TEXT1 = "This text was assigned to the Text property _
of Text1 "
In the following example, whenever the user clicks a file in the File list box, the Label1 Caption property is set to the FileName property of File1:
Private Sub File1_click ()
Label1 = File1
End Sub
Note Because the readability of the code is slightly affected by the use of the control value, the examples in this guide do not use control values, but rather explicitly refer to the properties of the control. Both methods can be used to write code that allows you to consider using control values without causing reading difficulties.

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.