c++wxwidgetswxtextctrl

wxTextCtrl new line issues


I'm fighting against an anoying problem with my wxTextCtrl. Whatever I try, there is no way to add a new line. wxTextCtrl diplay a square character instead of a new line.
Here is the relevant code :

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");  

And i get :

Some text◻◻New line◻◻An other new line◻◻Again a new line

First I thought there was a problem with the Multiline property but detail->IsMultiLine() return true

any help will be appreciated,


Solution

  • You must specify the Multiline property when you constrcut the object. You can not set this afterwards.

    From the wxWidgets documentation it mentions this specifically:

    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.

    Instead of:

    detail->SetWindowStyle(wxTE_MULTILINE);
    

    this should work:

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