【问题标题】:Writing end of line to wxTextCtrl将行尾写入 wxTextCtrl
【发布时间】: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();
}

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

【问题讨论】:

    标签: c++ wxwidgets


    【解决方案1】:

    您需要使用wxTE_MULTILINE 样式创建wxTextCtrl。然后,您通常只需要\n,它将为每个平台正确解释。

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 2021-12-15
      • 2011-10-19
      • 2018-10-10
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多