Button - Kirix Documentation

Developer Resources

Button

Overview

The Button class represents a button control which can be added to a window. It can be clicked by the user using the mouse, or activated by the keyboard if the control has keyboard focus. When the button is pushed, the click event is fired.

Base Class

FormControl

Constructor

Button(text : String, x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)

Arguments

text
The text to be shown on the control.
x_pos
The x position of the control.
y_pos
The y position of the control.
width
The width of the control.
height
The height of the control.

Events

Button.click
Fired when the button is clicked.

Methods

Button.getLabel
Returns the button's current label text.
Button.setDefault
Sets whether the button is a form's 'default' button
Button.setLabel
Sets the label text on the button.

Inherited Methods

FormControl.captureMouse
Captures the mouse on this form control.
FormControl.disablePaint
Disables the window from redrawing itself.
FormControl.enablePaint
Enables the window to redraw itself.
FormControl.getBackgroundColor
Gets the background color of the form control.
FormControl.getClientSize
Gets the client size of the form control.
FormControl.getEnabled
Indicates whether or not a form control is enabled.
FormControl.getFont
Gets the default font for the text of form control.
FormControl.getForegroundColor
Gets the foreground color of the form control.
FormControl.getMaxSize
Gets the maximum size of the form control.
FormControl.getMinSize
Gets the minimum size of the form control.
FormControl.getMousePosition
Gets the mouse position relative to this form control.
FormControl.getNativeHandle
Gets the native handle of the window/control
FormControl.getPosition
Gets the position of a form control.
FormControl.getSize
Gets the size of the form control.
FormControl.invalidate
Invalidates a form control, which will cause it to be repainted on the next paint event.
FormControl.refresh
Refreshes a form control, which immediately repaints the entire form control.
FormControl.releaseMouse
Releases the mouse from being captured on this form control.
FormControl.setBackgroundColor
Sets the background color of the form control.
FormControl.setClientSize
Sets the client size of a form control.
FormControl.setEnabled
Enables or disables the form control.
FormControl.setFocus
Sets the focus to the form control.
FormControl.setFont
Sets the default font for the text of the form control.
FormControl.setForegroundColor
Sets the foreground color of the form control.
FormControl.setMaxSize
Sets the maximum size of a form control.
FormControl.setMinSize
Sets the minimum size of a form control.
FormControl.setPosition
Sets the position of a form control relative to the the form control's parent.
FormControl.setSize
Sets the size of a form control.
FormControl.show
Shows or hides the form control.
FormControl.update
Updates a form control, which will immediately repaint any invalid areas.

Example

// create an instance of our derived MyForm class
var f = new MyForm;
f.show();
Application.run();

// create our own class derived from Form
class MyForm extends Form
{
    function MyForm()
    {
        // call the constructor on the base class Form
        super("Button Example", 100, 100, 200, 100);

        // create a button and add the button to our form
        var button = new Button("Exit", 60, 20, 80, 24);
        this.add(button);

        // when the button is clicked, call the onButtonClicked
        // event handler on this class
        button.click.connect(this, onButtonClicked);
    }

    function onButtonClicked()
    {
        // when the button is clicked, exit the application
        Application.exit();
    }
}

Button.getLabel

function Button.getLabel() : String

Returns

The button's current label text.

Description

Returns the button's current label text.

Button.setDefault

function Button.setDefault()

Description

Sets a button as a form's 'default' button. A default button is activated whenever the enter key is pressed when a form is focused.

Button.setLabel

function Button.setLabel(text : String)

Arguments

text
The new label text

Description

Sets the button's label text to the string specified in the text parameter.