Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 3

Important Properties of the CommandButton Control

Along with the TextBox and Label controls, the CommandButton control is one of the most familiar sights in a Windows application.

The main function of the CommandButton control is to run code when the user clicks on it. You should keep the following points in mind when programming with CommandButton properties:

  • You should always change the Caption property of a CommandButton. The Caption property contains the text displayed on the CommandButton. This property can be changed at design time and runtime.
  • The Cancel property is a Boolean type. It allows VB to associate the Escape key with the CommandButton's Click event procedure. Thus if you set Cancel to True, the Click event procedure fires when the user presses the Escape key. Cancel buttons are usually associated the with the Escape key.

    Notice that the Click event itself does not fire in this case. Instead only the Click event procedure runs. There is a difference when only the event procedure runs and the event itself does not fire. The most noticeable difference is that the focus does not change to the CommandButton when only the event procedure runs—as it would if the event itself had fired.
  • The Default property is a Boolean type. It allows VB to associate the Enter key with the CommandButton's Click event procedure. Thus, if you set Default to True, the Click event procedure will run if the user presses the Enter key. OK buttons are commonly associated with the Enter key.

    The comment made about the relation between the Cancel property's Click event and Click event procedure also applies to the Default property (i.e., the event procedure will fire, but the event itself will not run).
  • Only one CommandButton on a form can have its Default property set to True at a time. If you set one CommandButton to be the default, all other buttons will have their Default property set to False. The same rule applies for the Cancel property.
  • The Value property (the Default property for the CommandButton) is available only at runtime. If you set the Value property to True within your code, the CommandButton's Click event procedure runs. Notice that, as in our comments for the Cancel and Default property, we say here that the Click event procedure will run, but the Click event will not fire. Since Value is the CommandButton's Default property, code such as

    CmdOK = True

    would cause the CommandButton's Click event procedure to run

NOTE: CommandButton controls have a BackColor property that only takes noticeable effect when the Style property has been set to 1 - vbGraphical.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved