News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

neatest way to add multiline text to wxMessageDialog

Started by bdad, January 04, 2023, 12:26:32 AM

Previous topic - Next topic

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

#1
This is nearly OT here.

You can append wxStrings

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

or

wxString LongMessage;
LongMessage << "First line\n";
LongMessage << "Second line";

or use the preprocessor string chaining feature

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.

wxString LongMessage(_(
    "First line\n"
    "Second line"));


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.