VB6 Tutorial 13: The Command Button

By | 2018-04-01

You are going to learn about the command button control in this lesson. The command button control is a very common one. You need it every now and then in your program. So, lets have a look at some properties including a run-time property.

Properties of the Command Button

  • Cancel: Indicates whether a command button is the cancel button on the form. That means, if you press ESC key from keyboard, the CommandButton will be fired if the ‘Cancel’ property is set to true.
  • Default: Indicates whether a command button is the default button on the form. That means, if you press ENTER key from keyboard, the CommandButton will be fired if the ‘Default’ property is set to true.
  • MouseIcon: Sets a custom mouse icon.
  • MousePointer: Sets the type of mouse pointer that will be shown when the mouse pointer is over the button.
  • Picture: Sets an image to be displayed when the ‘style’ property is set to 1.

Run-time property of CommandButton

Value

The value property sets or returns the state of the control. That means , value is true if the CommandButton is pressed. This property is useful for programmatically clicking a button. Set the Name properties to cmdButton1 and cmdButton2. The default Name properties are Command1 and Command2.

Example

Private Sub cmdButton1_Click()
    Print "Hello"
End Sub

Private Sub cmdButton2_Click()
    cmdButton1.Value = True
End Sub

When you click on Button2, Button1 is clicked programmatically, then it prints “Hello”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.