wxTextCtrl新行问题

wxTextCtrl new line issues

本文关键字:问题 新行 wxTextCtrl      更新时间:2023-10-16

我正在与wxTextCtrl的恼人问题作斗争。无论我怎么尝试,都没有办法添加新的一行。wxTextCtrl显示一个方框字符,而不是一个新的行。
以下是相关代码:

wxTextCtrl  * detail = new wxTextCtrl (this,wxID_ANY);
detail->SetWindowStyle(wxTE_MULTILINE);
detail->SetEditable(false);
detail->AppendText("Some text");
detail->AppendText("n New line");
detail->AppendText("n An other new linen");
detail->AppendText("Again a new line");  

我得到:

一些文本◻◻◻◻另一个新行◻◻又是一个新行

首先我认为有一个问题与Multiline属性,但detail->IsMultiLine()返回true

在构造对象时必须指定Multiline属性。

wxWidgets文档中特别提到了这一点:

Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY, wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but not wxMSW. The other styles can be only set during control creation.

代替:

detail->SetWindowStyle(wxTE_MULTILINE);

这个应该可以工作:

wxTextCtrl(this,wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);