how to set font and size for my program? Topic is solved
-
- Earned a small fee
- Posts: 17
- Joined: Thu Jul 01, 2010 2:23 pm
how to set font and size for my program?
becouse it uses system size and font and on systems with big fonts GUI becomes a mess
VC++ 2008
-
- Super wx Problem Solver
- Posts: 442
- Joined: Tue May 06, 2008 4:52 pm
- Location: France
Each graphical control (text control, combo box, frame, ...) inherit from wxWindow. This class contains a SetFont method. You just have to create your wxFont and applied it :
Code: Select all
wxFont myFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
myWindow->SetFont(myFont);
Jérémie
-
- Earned a small fee
- Posts: 17
- Joined: Thu Jul 01, 2010 2:23 pm
doesn't work =\
- doesn't change anything
and if i place it in frame constructor MyFrame::MyFrame() it crashes
Code: Select all
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
setlocale( LC_NUMERIC, "English" );
MyFrame *frame = new MyFrame(NULL, _T("My Programs title"), 350, 350, 500, 400);
wxFont myFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
frame->SetFont(myFont);
frame->Show(true);
return true;
}
and if i place it in frame constructor MyFrame::MyFrame() it crashes
VC++ 2008
-
- Super wx Problem Solver
- Posts: 442
- Joined: Tue May 06, 2008 4:52 pm
- Location: France
-
- Earned a small fee
- Posts: 17
- Joined: Thu Jul 01, 2010 2:23 pm
how do you use wxDC::SetFont() ? i gives me error "illegal call of non-static member function"jfouche wrote:What does contain your frame ?
Do you draw inside ? If you draw with a DC, the documentation tolds you the given font will not be used. You must use wxDC::SetFont() instead.
I suggest you to try with a simple wxStaticText in your frame, and see if it's OK. If not, post some code.
and my frame do not draw, just a panel with text and checkboxes
Code: Select all
MyFrame::MyFrame(wxFrame *frame, wxChar * title, int x, int y, int w, int h)
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Veto::OnClose));
SetIcon(wxICON(sample));
wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(Minimal_About, "&About...\tF1", "Show about dialog");
fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, "&File");
menuBar->Append(helpMenu, "&Help");
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText("Status!");
wxPanel *panel = new wxPanel(this, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
wxCheckBox box_box = new wxCheckBox( panel, ID_SEEDER, wxT("my checkbox"), wxPoint(100, 100), wxDefaultSize, 0 );
...
VC++ 2008
-
- Super wx Problem Solver
- Posts: 442
- Joined: Tue May 06, 2008 4:52 pm
- Location: France
Does your close event works ? I suggest you to do :
For your pb, does the following code works ?
For the wxDC::SetFont(...), it's usefull if you manage the paint event (but it's not the case for you). You must create a DC and call the SetFont method on the created DC (but as I said, do not use it if you don't need to paint).
Code: Select all
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MyFrame::OnClose), NULL, this);
...
void MyFrame::OnClose(wxCloseEvent& event)
{
Destroy();
}
Code: Select all
box_box->SetFont(myFont); // As defined before
Jérémie
-
- Earned a small fee
- Posts: 17
- Joined: Thu Jul 01, 2010 2:23 pm
Yes.Does your close event works ?
Code: Select all
box_box->SetFont(myFont);
and i finally found a way, i did ->SetFont on the panel
panel->SetFont(MyFont);
VC++ 2008
-
- Super wx Problem Solver
- Posts: 442
- Joined: Tue May 06, 2008 4:52 pm
- Location: France
-
- Site Admin
- Posts: 6695
- Joined: Thu Sep 28, 2006 12:23 am