Version: 2.9.4
Public Member Functions | Static Public Member Functions
wxButton Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/button.h>

Inheritance diagram for wxButton:

Detailed Description

A button is a control that contains a text string, and is one of the most common elements of a GUI.

It may be placed on a dialog box or on a wxPanel panel, or indeed on almost any other window.

By default, i.e. if none of the alignment styles are specified, the label is centered both horizontally and vertically. If the button has both a label and a bitmap, the alignment styles above specify the location of the rectangle combining both the label and the bitmap and the bitmap position set with wxButton::SetBitmapPosition() defines the relative position of the bitmap with respect to the label (however currently non-default alignment combinations are not implemented on all platforms).

Since version 2.9.1 wxButton supports showing both text and an image (currently only when using wxMSW, wxGTK or wxOSX/Cocoa ports), see SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the previous wxWidgets versions this functionality was only available in (the now trivial) wxBitmapButton class which was only capable of showing an image without text.

A button may have either a single image for all states or different images for the following states (different images are not currently supported under OS X where the normal image is used for all states):

All of the bitmaps must be of the same size and the normal bitmap must be set first (to a valid bitmap), before setting any other ones. Also, if the size of the bitmaps is changed later, you need to change the size of the normal bitmap before setting any other bitmaps with the new size (and you do need to reset all of them as their original values can be lost when the normal bitmap size changes).

The position of the image inside the button be configured using SetBitmapPosition(). By default the image is on the left of the text.

Please also notice that GTK+ uses a global setting called gtk-button-images to determine if the images should be shown in the buttons at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no images will be shown, consistently with the native behaviour.

Styles

This class supports the following styles:

Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxCommandEvent& event)

Event macros for events emitted by this class:

Library:  wxCore
Category:  Controls

Appearance:
wxMSW appearancewxGTK appearancewxMac appearance
wxMSW appearancewxGTK appearancewxMac appearance
参照:
wxBitmapButton

Public Member Functions

 wxButton ()
 Default ctor.
 wxButton (wxWindow *parent, wxWindowID id, const wxString &label=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxButtonNameStr)
 Constructor, creating and showing a button.
bool Create (wxWindow *parent, wxWindowID id, const wxString &label=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxButtonNameStr)
 Button creation function for two-step creation.
bool GetAuthNeeded () const
 Returns true if an authentication needed symbol is displayed on the button.
wxString GetLabel () const
 Returns the string label for the button.
void SetAuthNeeded (bool needed=true)
 Sets whether an authentication needed symbol should be displayed on the button.
virtual wxWindowSetDefault ()
 This sets the button to be the default item in its top-level window (e.g.
void SetLabel (const wxString &label)
 Sets the string label for the button.

Static Public Member Functions

static wxSize GetDefaultSize ()
 Returns the default size for the buttons.

List of all members.


Constructor & Destructor Documentation

wxButton::wxButton ( )

Default ctor.

wxButton::wxButton ( wxWindow parent,
wxWindowID  id,
const wxString label = wxEmptyString,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxButtonNameStr 
)

Constructor, creating and showing a button.

The preferred way to create standard buttons is to use default value of label. If no label is supplied and id is one of standard IDs from this list, a standard label will be used. In other words, if you use a predefined wxID_XXX constant, just omit the label completely rather than specifying it. In particular, help buttons (the ones with id of wxID_HELP) under Mac OS X can't display any label at all and while wxButton will detect if the standard "Help" label is used and ignore it, using any other label will prevent the button from correctly appearing as a help button and so should be avoided.

In addition to that, the button will be decorated with stock icons under GTK+ 2.

Parameters:
parentParent window. Must not be NULL.
idButton identifier. A value of wxID_ANY indicates a default value.
labelText to be displayed on the button.
posButton position.
sizeButton size. If the default size is specified then the button is sized appropriately for the text.
styleWindow style. See wxButton class description.
validatorWindow validator.
nameWindow name.
参照:
Create(), wxValidator

Member Function Documentation

bool wxButton::Create ( wxWindow parent,
wxWindowID  id,
const wxString label = wxEmptyString,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxButtonNameStr 
)

Button creation function for two-step creation.

For more details, see wxButton().

bool wxButton::GetAuthNeeded ( ) const

Returns true if an authentication needed symbol is displayed on the button.

注意:
This method always returns false if the platform is not Windows Vista or newer.
参照:
SetAuthNeeded()
Since:
2.9.1
static wxSize wxButton::GetDefaultSize ( ) [static]

Returns the default size for the buttons.

It is advised to make all the dialog buttons of the same size and this function allows to retrieve the (platform and current font dependent size) which should be the best suited for this.

wxString wxButton::GetLabel ( ) const [virtual]

Returns the string label for the button.

参照:
SetLabel()

Reimplemented from wxControl.

Reimplemented in wxCommandLinkButton.

void wxButton::SetAuthNeeded ( bool  needed = true)

Sets whether an authentication needed symbol should be displayed on the button.

注意:
This method doesn't do anything if the platform is not Windows Vista or newer.
参照:
GetAuthNeeded()
Since:
2.9.1
virtual wxWindow* wxButton::SetDefault ( ) [virtual]

This sets the button to be the default item in its top-level window (e.g.

the panel or the dialog box containing it).

As normal, 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, and wxTopLevelWindow::SetDefaultItem().

注意:
Under Windows, only dialog box buttons respond to this function.
Returns:
the old default item (possibly NULL)
void wxButton::SetLabel ( const wxString label) [virtual]

Sets the string label for the button.

Parameters:
labelThe label to set.

Reimplemented from wxControl.

Reimplemented in wxCommandLinkButton.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines