【发布时间】:2020-05-11 20:15:21
【问题描述】:
我试图将文本写入 wxWidgets 应用程序中的 wxTextctrl 对象。示例代码如下。出于某种原因,我没有设法换行。我在网上找到的大多数示例都做了一些在这里不起作用的事情。
代码:
#include "wx/wx.h"
using namespace std;
class MainWindow : public wxFrame {
public:
MainWindow(const wxString& title);
wxTextCtrl* textctrl;
};
class MyApp : public wxApp {
public:
virtual bool OnInit();
MainWindow* main_window;
};
MainWindow::MainWindow(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(280, 180)) {
// Add text window:
textctrl =
new wxTextCtrl(this, -1, wxT(""), wxPoint(-1, -1), wxSize(250, 150));
// This writes to the middle of the text white space, but does not understand
// endl \n or \r\n
ostream log_stream(textctrl);
log_stream << "Hey Joe! \n";
log_stream << "Buckle up!\r\n";
log_stream << "Lorem ipsum dolor sit amet" << endl;
wxStreamToTextRedirector redirect(textctrl);
cout << "Not yet " << endl;
cout << "One more \n";
cout << "Just one more \r\n";
cout << "Fine, I quit.";
Centre();
}
此外,由于窗口大小,文本不会自动中断。
【问题讨论】: