How to make \n appear in wxTextCtrl? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

How to make \n appear in wxTextCtrl?

Post by Tapsa »

I have constructed wxTextCtrls using:

Code: Select all

wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, dimensions, wxTE_MULTILINE)
\n in the strings is neither converted to actual new line nor displayed in any way. It is completely omitted in the wxTextCtrl. How can I make it appear as \n or as new line?

I'm using 2.8.12.
DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 231
Joined: Mon Jan 19, 2015 1:45 pm

Re: How to make \n appear in wxTextCtrl?

Post by DenDev »

It works in wx version 3.0.2. You might try to "\r\n" instead since that is the default line break sequence in windows.
I have a bad habbit of not testing the code I post :D
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to make \n appear in wxTextCtrl?

Post by Tapsa »

They are strings loaded from DLL. I would rather have them shown as they are.
Block\nPrinting
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to make \n appear in wxTextCtrl?

Post by doublemax »

What exactly does the string contain, the real newline code (0x0a) or the characters "\" and "n"?
Use the source, Luke!
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to make \n appear in wxTextCtrl?

Post by Tapsa »

Using hex viewer I can see "42 00 6C 00 6F 00 63 00 6B 00 0A 00 50 00 72 00 69 00 6E 00 74 00 69 00 6E 00 67 00" so yes it has 0A aka new line.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to make \n appear in wxTextCtrl?

Post by doublemax »

That makes sense, because i don't think the text control itself converts "\n" to 0x0a.

If you want to display 0x0a as "\n", you'll have to replace it in the string. I don't think you can tell the text control to display it differently.
Use the source, Luke!
DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 231
Joined: Mon Jan 19, 2015 1:45 pm

Re: How to make \n appear in wxTextCtrl?

Post by DenDev »

Does a replace do any change?

Code: Select all

wxString str = (set to whatever);
str.Replace("\n", "\r\n");
text_ctrl->AppendText(str);
I have a bad habbit of not testing the code I post :D
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to make \n appear in wxTextCtrl?

Post by Tapsa »

Thank you. I had lots to do so took a while before testing this.
Apparently Resource Hacker and Resource Tuner both replace 0x0A with \n.
DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 231
Joined: Mon Jan 19, 2015 1:45 pm

Re: How to make \n appear in wxTextCtrl?

Post by DenDev »

\n is just a C-style escape character for 0x0A and equals to \x0a, \r\n equals to \x13\x0a :-)
I have a bad habbit of not testing the code I post :D
Post Reply