【发布时间】:2021-12-05 15:36:35
【问题描述】:
我想让 Hello World 文本变大,但我不知道怎么做
我尝试使用staticText1->SetSize(32)、staticText1->SetSize(wxSize(32,32)) 并将wxDefaultSize 替换为wxSize(32, 32),但没有任何效果(我没有收到错误,它只是不会改变文本大小)
这是我当前的代码:
#include <wx/wx.h>
class Frame : public wxFrame
{
private:
wxStaticText* staticText1 = new wxStaticText(this, wxID_ANY, "Hello, World!", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
public:
Frame() : wxFrame(nullptr, wxID_ANY, "spageta", wxDefaultPosition, wxSize(400, 200)) {
staticText1->SetForegroundColour(wxTheColourDatabase->Find("Black"));
}
};
class App : public wxApp
{
public:
App();
private:
wxFrame* NewFrame = nullptr;
public:
virtual bool OnInit();
};
App::App()
{
}
bool App::OnInit()
{
NewFrame = new Frame();
NewFrame->Show(true);
return true;
}
wxIMPLEMENT_APP(App);
【问题讨论】:
-
在 wxFrame 的构造函数中尝试以下操作:
wxFont font = staticText1->GetFont(); font.SetSize( 32 ); staticText1->SetFont( font ); -
@Igor 我试过了,但我得到了这个错误
error: 'class wxFont' has no member named 'SetSize'; did you mean 'SetStyle'? -
抱歉,请使用
SetPointSize()/SetPixelSize()。一个或另一个。 -
@Igor 谢谢,这工作:)