【问题标题】:wxTextCtrl new line issueswxTextCtrl 换行问题
【发布时间】:2013-05-17 04:17:32
【问题描述】:

我正在与我的 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 line\n");
detail->AppendText("Again a new line");  

我得到:

一些文字◻◻换行◻◻另一个换行◻◻再换行

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

任何帮助将不胜感激,

【问题讨论】:

    标签: c++ wxwidgets wxtextctrl


    【解决方案1】:

    在构造对象时必须指定 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);
    

    【讨论】:

    • 非常感谢您提供的精确度,我没有阅读过文档的这一部分,我的错。无论如何,多亏了你,它现在可以工作了。
    猜你喜欢
    • 2021-09-20
    • 2015-03-05
    • 2012-09-14
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 2014-02-08
    • 2021-05-29
    • 2018-11-19
    相关资源
    最近更新 更多