Reputation: 87
I wanted to ask how to resize a button at a particular position from a point heres what i wrote however the button appears on the whole screen,please help
i am using a .cpp file instead of the one .h and .cpp
enum
{
BUTTON_Generate = 2,
};
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( _("Key Generator"), wxPoint(1, 1),wxSize(450, 450));
frame->Connect( BUTTON_Generate, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)
&MyFrame::OnAbout);
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame( NULL, -1, title, pos, size )
{
GenerateKey = new wxButton(this, BUTTON_Generate, _T("Generate Key"), wxPoint(200,
200), wxSize(10,10), 0);
}
however if i write : another button as:
GenerateKey2 = new wxButton(this, BUTTON_Generate, _T("Generate Key"), wxPoint(200,
200), wxSize(10,10), 0);
it shows the both the buttons aligned at the points specified however in the case of declaration of a single button it shows the button stretched on the whole frame, why is it so?
Emma
Upvotes: 0
Views: 823
Reputation: 20472
I believe the problem is that you have assigned the value 2 to the window id of your button. This value is used internally by wxWidgets for something else.
To set up a window ids that do not conflict with IDs used by wxWidgets, do something along these lines:
// IDs for the controls and the menu commands
enum ControlIDs {
lastwxwidgetid = wxID_HIGHEST,
BUTTON_Generate;
};
This will force you new IDs to be higher than used by wxWidgets.
Seems that VZ.'s answer is correct. However, you should still be careful about assigning window IDs that conflict - eventually you will hit some odd behaviour that will be very hard to debug.
Upvotes: 1
Reputation: 22688
As mentioned in wxFrame documentation, the only child of wxFrame
will be always resized to fit its entire client area as this is what you typically want.
Unless, that is, you handle the resize event yourself.
wxFrame processes the following events:
wxEVT_SIZE: if the frame has exactly one child window, not counting the status and toolbar, this child is resized to take the entire frame client area. If two or more windows are present, they should be laid out explicitly either by manually handling wxEVT_SIZE or using sizers;
This is one of the reasons (the other being that you need to use wxPanel
for keyboard navigation to work) for creating a wxPanel
as child of the frame and then creating all the controls as children of this panel.
BTW, consider using sizers instead of absolute positioning that won't work well in any case.
Upvotes: 1