Contents Up Previous Next

wxButton: wxItem

A button is a panel item that contains a text string or bitmap, and is one of the commonest elements of a GUI. It may be placed on a dialog box or panel.

wxButton::wxButton
wxButton::~wxButton
wxButton::Create
wxButton::SetDefault
wxButton::SetLabel


wxButton::wxButton

void wxButton(wxPanel *parent, wxFunction func, char *label,
int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "button")

void wxButton(wxPanel *parent, wxFunction func, wxBitmap *wxBitmap,
int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "button")

Constructor, creating and showing a button. The parent must be a valid panel or dialog box pointer.

func may be NULL; otherwise it is used as the callback for the button. Note that the cast (wxFunction) must be used when passing your callback function name, or the compiler may complain that the function does not match the constructor declaration. See wxFunction.

The parameters x and y are used to specify an absolute position, or a position after the previous panel item if omitted or default.

If width or height are omitted (or are less than zero), an appropriate size will be used for the item. The style parameter is reserved for future use. The name parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual buttons.

If the first form is used, the label will be shown on the button. If the seond form is used, the bitmap will be used.


wxButton::~wxButton

void ~wxButton(void)

Destructor, destroying the button.


wxButton::Create

void Create(wxPanel *parent, wxFunction func, char *label,
int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "button")

void Create(wxPanel *parent, wxFunction func, wxBitmap *wxBitmap,
int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "button")

Button creation functions called by the button constructors. Call these when a derived button class uses the zero-argument wxButton constructor, but can reuse the existing button creation code. See wxButton::wxButton for details.


wxButton::SetDefault

void SetDefault(void)

This sets the button to be the default item for the panel or dialog box. Under XView, the default item is highlighted, and pressing the return key executes the callback for the item (but with no visual feedback, and only if a text item does not have the focus).

Under MS Windows, only dialog box buttons respond to this function. As normal under MS Windows and Motif, pressing return causes the default button to be depressed when the return key is pressed. See also wxWindow::SetFocus which sets the keyboard focus for windows and text panel items, wxPanel::OnDefaultAction and wxPanel::GetDefaultItem.

Note that under Motif, calling this function immediately after creation of a button and before the creation of other buttons will cause misalignment of the row of buttons, since default buttons are larger. To get around this, call SetDefault after you have created a row of buttons: wxWindows will then set the size of all buttons currently on the panel to the same size.


wxButton::SetLabel

void SetLabel(wxBitmap *label)

void SetLabel(char *label)

Sets the string or bitmap label for a button.