将行尾写到wxTextCtrl

问题描述 投票:0回答:1

我试图将文本写入wxTextctrl应用程序中的wxWidgets对象。示例代码如下。由于某种原因,我无法获得换行符。我在网上发现的大多数示例都执行了其中一项操作,而这在这里不起作用。

What I'm getting

代码:

#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();
}

此外,由于窗口大小,文本不会自动中断。

c++ wxwidgets
1个回答
0
投票

您需要以wxTextCtrl样式创建wxTE_MULTILINE。然后,您通常只需要\n,即可为每个平台正确解释。

© www.soinside.com 2019 - 2024. All rights reserved.