简体   繁体   English

将行尾写入 wxTextCtrl

[英]Writing end of line to wxTextCtrl

I was trying to write text to a wxTextctrl object in a wxWidgets application.我试图在wxWidgets应用程序中将文本写入wxTextctrl object。 Example code is below.示例代码如下。 For some reason, I'm not managing to get a line break.出于某种原因,我没有设法换行。 And most examples I've found online did one of the things that aren't working here.我在网上找到的大多数例子都做了一些在这里不起作用的事情。

我得到了什么

The code:编码:

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

Also, the text is not breaking automatically due to the window size.此外,由于 window 大小,文本不会自动中断。

You need to create wxTextCtrl with wxTE_MULTILINE style.您需要使用wxTE_MULTILINE样式创建wxTextCtrl You then normally only need \n which will be correctly interpreted for each platform.然后,您通常只需要为每个平台正确解释的\n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM