CommandButton Control (VBCCRCmdBtn)
VBCCRCmdBtn is an enhanced version of the standard CommandButton control, offering more functionality and better visual effects.
Properties
Key Properties
Caption: Text displayed on the buttonDefault: Sets whether it's the form's default buttonCancel: Sets whether it's the cancel button (triggered by ESC key)Picture: Image displayed on the buttonStyle: Button styleStandard- Standard buttonGraphical- Graphical button
ImageAlignment: Image alignmentTextAlignment: Text alignmentEnabled: Enable/disable buttonForeColor: Text colorBackColor: Background color
Methods
Main Methods
Click(): Programmatically trigger button clickSetFocus(): Set focus to the buttonRefresh(): Refresh button display
Events
Click(): Triggered when button is clickedGotFocus(): Triggered when focus is receivedLostFocus(): Triggered when focus is lostMouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single): Triggered when mouse button is pressedMouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single): Triggered when mouse button is releasedMouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single): Triggered when mouse moves
Code Examples
Basic Usage
vb
Private Sub Form_Load()
' Basic button setup
With CommandButton1
.Caption = "Click Me"
.Default = True
.Enabled = True
End With
End Sub
Private Sub CommandButton1_Click()
MsgBox "Button was clicked!"
End SubGraphical Button
vb
Private Sub SetupGraphicalButton()
With CommandButton1
.Style = Graphical
Set .Picture = LoadPicture("button.ico")
.ImageAlignment = ImageAlignmentCenter
.TextAlignment = TextAlignmentBottom
.Caption = "Graphical Button"
End With
End SubDynamic State Control
vb
Private Sub UpdateButtonState(ByVal IsEnabled As Boolean)
With CommandButton1
.Enabled = IsEnabled
If IsEnabled Then
.Caption = "Click to Submit"
.ForeColor = vbBlack
Else
.Caption = "Processing..."
.ForeColor = vbGrayText
End If
End With
End SubCommon Use Cases
Submit Form Button
vb
Private Sub SetupSubmitButton()
With cmdSubmit
.Caption = "Submit Form"
.Default = True
.Enabled = False ' Initially disabled
End With
End Sub