Visual Basic CommandButton Control

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.

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.