Author Topic: neatest way to add multiline text to wxMessageDialog  (Read 2098 times)

Offline bdad

  • Multiple posting newcomer
  • *
  • Posts: 29
neatest way to add multiline text to wxMessageDialog
« 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.
« Last Edit: January 04, 2023, 12:28:41 am by bdad »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: neatest way to add multiline text to wxMessageDialog
« Reply #1 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"));
« Last Edit: January 04, 2023, 10:52:04 am by Miguel Gimenez »

Offline bdad

  • Multiple posting newcomer
  • *
  • Posts: 29
Re: neatest way to add multiline text to wxMessageDialog
« Reply #2 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,

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: neatest way to add multiline text to wxMessageDialog
« Reply #3 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.

Offline bdad

  • Multiple posting newcomer
  • *
  • Posts: 29
Re: neatest way to add multiline text to wxMessageDialog
« Reply #4 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.