我想将我的 wxStaticText 集中在 wxWindow 上,但似乎这不起作用。这是我的代码:
#include <iostream>
#include <wx/wx.h>
#include <wx/gbsizer.h>
using namespace std;
class MyApp: public wxApp
{
virtual bool OnInit();
};
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame(NULL,wxID_ANY,wxT("fenetre"));
wxWindow *win = new wxWindow(frame,wxID_ANY);
win->SetWindowStyle(wxBORDER_RAISED);
wxStaticText *text = new wxStaticText(win,wxID_STATIC,wxT("Mon texte"));
wxBoxSizer *b = new wxBoxSizer(wxVERTICAL);
wxGridBagSizer *box = new wxGridBagSizer();
wxButton *button = new wxButton(frame,wxID_ANY,wxT("salut"));
b->Add(text,0,wxALIGN_CENTRE);
win->SetSizer(b);
box->Add(win,wxGBPosition(0,0),wxDefaultSpan,wxALL|wxALIGN_CENTER|wxGROW);
box->Add(button,wxGBPosition(1,0),wxDefaultSpan,wxALL|wxGROW);
box->AddGrowableCol(0);
box->AddGrowableRow(0);
box->AddGrowableRow(1);
frame->SetSizer(box);
frame->Show(true);
return true;
}
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
我不知道出了什么问题,但是 wxStaticText 并没有以我的 wxWindow 为中心。请告诉我缺少什么。
我的 wxStaticText 代码直接在框架上。
#include <wx/gbsizer.h>
using namespace std;
class MyApp: public wxApp
{
virtual bool OnInit();
};
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame(NULL,wxID_ANY,wxT("fenetre"));
//wxFrame *win = new wxFrame(frame,wxID_ANY,wxT("hh"));
wxStaticText *text = new wxStaticText(frame,wxID_STATIC,wxT("Mon texte"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER_HORIZONTAL);
text->SetWindowStyle(wxBORDER_RAISED);
//wxBoxSizer *b = new wxBoxSizer(wxVERTICAL);
wxGridBagSizer *box = new wxGridBagSizer();
wxButton *button = new wxButton(frame,wxID_ANY,wxT("salut"));
//b->Add(text,0,wxALIGN_CENTRE);
//win->SetSizer(b);
box->Add(text,wxGBPosition(0,0),wxDefaultSpan,wxALL|wxALIGN_CENTER);
box->Add(button,wxGBPosition(1,0),wxDefaultSpan,wxALL|wxGROW);
box->AddGrowableCol(0);
box->AddGrowableRow(0);
box->AddGrowableRow(1);
frame->SetSizer(box);
frame->Show(true);
return true;
}
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)