-1

I want each Total displayed on a different line in the box but at the moment it keep overlapping. Could someone please show me the way?

    private void SummaryButton_Click(object sender, EventArgs e)
    {
        TotalMoniesTaken = AmountDue + TotalMoniesTaken;
        TotalGuests = NumberOfGuests + TotalGuests;
        TotalLunchBookings = NumberOfGuests + TotalLunchBookings;
        TotalEarlyBookings = NumberOfGuests + TotalEarlyBookings;
        TotalLateBookings = NumberOfGuests + TotalLateBookings;
        TotalCornerTables = NumberOfGuests + TotalCornerTables;
        TotalWaiters = NumberOfGuests + TotalWaiters;

        MessageBox.Show("Total Monies Taken is €" + TotalMoniesTaken + 
                        "Total Number of Bookings = " + TotalGuests + 
                        "Total Lunch Bookings = " + TotalLunchBookings + 
                        "Total Early Bookings = " + TotalEarlyBookings +
                        "Total Late Bookings = " + TotalLateBookings + 
                        "Total Corner Tables = " + TotalCornerTables +
                        "Total Waiters = " + TotalWaiters);






    }
Sam Darkin
  • 1
  • 1
  • 1
  • 1
    [Put a `\n`](http://stackoverflow.com/questions/1015766/difference-between-n-and-environment-newline) in there? – GolezTrol Nov 21 '16 at 15:53

6 Answers6

4

Displaying this doesn't include a new line:

"Total Monies Taken is €" + TotalMoniesTaken

But this does:

"Total Monies Taken is €" + TotalMoniesTaken + Environment.NewLine
David
  • 208,112
  • 36
  • 198
  • 279
0

Add newlines to each one :

"Total Monies Taken is €" + TotalMoniesTaken + Environment.NewLine
"Total Number of Bookings = " + TotalGuests + Environment.NewLine

..etc

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122
0

There are a few ways that you can do this in C#, firstly you can use newlines in your string

MessageBox.Show("Total Monies Taken is €" + TotalMoniesTaken + 
                    "\nTotal Number of Bookings = " + TotalGuests + 
                    "\nTotal Lunch Bookings = " + TotalLunchBookings + 
                    "\nTotal Early Bookings = " + TotalEarlyBookings +
                    "\nTotal Late Bookings = " + TotalLateBookings + 
                    "\nTotal Corner Tables = " + TotalCornerTables +
                    "\nTotal Waiters = " + TotalWaiters);

Alternatively, you could use Environment.NewLine

MessageBox.Show("Total Monies Taken is €" + TotalMoniesTaken + Environment.NewLine + 
                    "Total Number of Bookings = " + TotalGuests + Environment.NewLine + 
                    "Total Lunch Bookings = " + TotalLunchBookings + Environment.NewLine + 
                    "Total Early Bookings = " + TotalEarlyBookings + Environment.NewLine + 
                    "Total Late Bookings = " + TotalLateBookings + Environment.NewLine + 
                    "Total Corner Tables = " + TotalCornerTables + Environment.NewLine +
                    "Total Waiters = " + TotalWaiters);
Alfie Goodacre
  • 2,753
  • 1
  • 13
  • 26
0

just use \n at the end of each line

MessageBox.Show("test1 \n test2 \n test3");
Ali
  • 53
  • 1
  • 7
0

You can do two ways:

1st one with \n:

Eg: string msg = "text\nwith two lines";

2nd way with Environment.NewLine:

Eg:string msg = "Text " + Environment.NewLine + "with two lines";
Chandana Kumara
  • 2,485
  • 1
  • 22
  • 25
0

Some of the newer C# features (not tested) MessageBox.Show( $@"Total Monies Taken is €{TotalMoniesTaken} Total Number of Bookings = {TotalGuests} ...");

Husain
  • 784
  • 1
  • 9
  • 22