The button control of VB

Source: Internet
Author: User

Using the CommandButton control

A command button control is used to start, break, or end a process. When clicked, a command is invoked that has been written to the Click event procedure.

Most Visual Basic applications have command buttons that allow users to click buttons to perform actions. When clicked, the button not only performs the appropriate action, but also looks like it is pressed and loosened, so it is sometimes called a push button.
More information for a simple example of a CommandButton control, see chapter III, "Click the button to perform action" in the forms, controls, and menus.

Add a command button to a form
One or more command buttons are most likely to be used in your application. Add a command button to a form just as you would a different control draw a button. You can adjust the size of the command button by using the mouse, or by setting the Height and Width properties.

Set Title
Use the Caption property to change the text displayed on a command button. At design time, you can set this property in the Properties window of the control. When you set the Caption property at design time, the button text is updated dynamically.
The Caption property contains a maximum of 255 characters. If the caption exceeds the width of the command button, it will be folded to the next line. However, if the control cannot hold its full length, the caption is clipped. You can change the font displayed on a command button by setting the Font property.

Create keyboard shortcuts
You can create an access key shortcut to a command button by using the Caption property, so you simply add a hyphen (&) before the letter that is the access key. For example, to create an access key for the title "Print", add a hyphen before the letter "P" and get "&print". At run time, the letter "P" is underlined and the ALT+P key is pressed to select the command button.
Note You should add two hyphens (&&) If you do not create an access key and you want the title to contain hyphens but do not create access keys. As a result, only one hyphen is displayed in the caption without underlining.

Specify the Default and Cancel properties
At the top of each form, you can select a command button as the default command button, which means that no matter which control on the form has the focus, the default button is clicked as long as the user presses the ENTER key. To specify a default command button, set its default property to True.
You can also specify the default Cancel button. When the Cancel property of the command button is set to True, the default button is clicked, regardless of which control in the form has the focus, and the ESC key is pressed.

Select a command button
At run time, you can use the mouse or keyboard to select a command button by using the following methods:
Click the button with the mouse.
Press the TAB key to move the focus to the button, and then press SPACEBAR or ENTER to select the button.
Press the access key for the command button (ALT + underlined letter).
If the command button is the default command button for a form, press ENTER to select the button, even if the focus is shifted to another control.
If the command button is the default Cancel button for the form, press the ESC key to select the button, even if the focus is shifted to another control.

Value Property
Whenever a command button is selected, its Value property is set to True and the Click event is triggered. False (default) indicates that the button is not selected. The Click event of a command button can be triggered in code with the Value property. For example:
Cmdclose.value = True

Click Event
Clicking the command button triggers the button's Click event and invokes code that has been written to the Click event procedure.
The MouseDown and MouseUp events are also generated when the command button is clicked. If you want to attach an event procedure to these related events, you should ensure that the operation does not collide. Control, these three event procedures occur in a different order. The order in which events occur in the CommandButton control is:
MouseDown, Click, MouseUp.
Note If a user tries to double-click a command button control, each click is handled separately; the command button control does not support double-clicking events.
For more information about the MouseDown and MouseUp events, see Chapter 11th, "Responding to mouse and keyboard events."

Enhance the visual effects of command buttons
command buttons like check boxes and option buttons, you can use the picture, DownPicture, and DisabledPicture properties to enhance visual effects by changing the Style property to set a value. This can happen, such as adding an icon or bitmap to a command button, or displaying a different image when you click or disable the control.

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.