User forums > General (but related to Code::Blocks)

neatest way to add multiline text to wxMessageDialog

(1/1)

bdad:
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.

Miguel Gimenez:
This is nearly OT here.

You can append wxStrings

--- Code: ---wxString LongMessage(
    wxString("First line\n")+
    wxString("Second line"));

--- End code ---
or

--- Code: ---wxString LongMessage;
LongMessage << "First line\n";
LongMessage << "Second line";

--- End code ---
or use the preprocessor string chaining feature

--- Code: ---wxString LongMessage(
    "First line\n"
    "Second line");

--- End code ---

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

--- End code ---

bdad:
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,

Miguel Gimenez:
It is OT because it is not related to C::B, but to plain C or wxWidgets.

bdad:
OK. Thanks for your answer. I'll have to try to differentiate, and sign up to a wxWidget forum.

Navigation

[0] Message Index

Go to full version