Knowledge Base 
Adding Controls to a CommandBar at run time 
 Thursday, November 21, 2024

Adding Controls to a CommandBar at run time

You can add controls to a commandbar at run time by using the CreateControl method of the CommandBar object.

This sample code illustrates how to add new commandbar controls at run time:

loButton = ThisForm.cmdBarStandard.CreateControl()
loButton.BeginGroup = .T.
loButton.Caption = "Sample Button"
loButton.SetPicture( "picture.bmp")
loButton.OnClick = "MessageBox( This.Caption)"
loButton.Visible = .T.
...
... set other properties here
...
&& required if commandbar was initialized earlier
ThisForm.cmdBarStandard.InitControl( m.loButton)