Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: bdad on January 04, 2023, 12:26:32 am

Title: neatest way to add multiline text to wxMessageDialog
Post by: bdad on January 04, 2023, 12:26:32 am
I need to show the message dialog with 6 or 7 sentences  on separate lines (accessed by a help button on the menu).
If I place them (using the \n for new line) into the 'MessageDialog1 = new wxMessageDialog' line, then the that line becomes rather long, making it awkward to modify during development.
What is a simple way of creating the wxString to be inserted therein, that shows a similar layout within the code as in the final message box on screen? I'm new to c++, newer still to wxWidgets/codeblocks so an example of the code to create the wxString would be nice. Thanks.
Title: Re: neatest way to add multiline text to wxMessageDialog
Post by: Miguel Gimenez on January 04, 2023, 10:28:35 am
This is nearly OT here.

You can append wxStrings
Code
wxString LongMessage(
    wxString("First line\n")+
    wxString("Second line"));
or
Code
wxString LongMessage;
LongMessage << "First line\n";
LongMessage << "Second line";
or use the preprocessor string chaining feature
Code
wxString LongMessage(
    "First line\n"
    "Second line");

EDIT: The last form is the best if you intend to use _() for translations, because you will get a full paragraph in POedit.
Code
wxString LongMessage(_(
    "First line\n"
    "Second line"));
Title: Re: neatest way to add multiline text to wxMessageDialog
Post by: bdad on January 04, 2023, 12:51:32 pm
Thanks. I'd spent ages struggling with different 'solutions' I'd found, and inventing a few of my own, to no avail, probably because I don't notice the detail in the syntax. I'm not sure as to why it would be OT,
Title: Re: neatest way to add multiline text to wxMessageDialog
Post by: Miguel Gimenez on January 04, 2023, 01:04:25 pm
It is OT because it is not related to C::B, but to plain C or wxWidgets.
Title: Re: neatest way to add multiline text to wxMessageDialog
Post by: bdad on January 04, 2023, 01:42:49 pm
OK. Thanks for your answer. I'll have to try to differentiate, and sign up to a wxWidget forum.