Command Button

From Apache OpenOffice Wiki
Jump to: navigation, search

The command button allows the user to perform an action by clicking the button. Usually a button carries a label that is set through the Label property of the control model:

  oDialogModel = oDialog.getModel()
  oButtonModel = oDialogModel.getByName("CommandButton1")
  oButtonModel.setPropertyValue("Label", "My Label")

or in short:

  oDialog.Model.CommandButton1.Label = "My Label"

The label can also be set using the setLabel method of the interface:

  oButton = oDialog.getControl("CommandButton1")
  oButton.setLabel("My Label")

or in short:

  oButton.Label = "My Label"

During runtime, you may want to enable or disable a button. This is achieved by setting the Enabled property to True or False. The PushButtonType property defines the default action of a button where 0 is the Default, 1 is OK, 2 is Cancel, and 3 is Help. If a button has a PushButtonType value of 2, it behaves like a cancel button, that is, pressing the button closes the dialog. In this case, the method execute() of the dialog returns with a value of 0. An OK button of PushButtonType 1 returns 1 on execute(). The property DefaultButton specifies that the command button is the default button on the dialog, that is, pressing the ENTER key chooses the button even if another control has the focus. The Tabstop property defines if a control can be reached with the TAB key.

The command button has the feature, to display an image by setting the ImageURL property, which contains the path to the graphics file.

  oButtonModel = oDialog.Model.CommandButton1
  oButtonModel.ImageURL = "file:///D:/Office60/share/gallery/bullets/bluball.gif"
  oButtonModel.ImageAlign = 2

All standard graphics formats are supported, such as .gif, .jpg, .tif, .wmf and .bmp. The property ImageAlign defines the alignment of the image inside the button where 0 is Left, 1 is Top, 2 is Right, and 3 is the Bottom. If the size of the image exceeds the size of the button, the image is not scaled automatically, but cut off. In this respect, the image control offers more functionality.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages