2016-11-21 2 views
-1

Ich möchte jedes Total auf einer anderen Linie in der Box angezeigt werden, aber im Moment überlappt es sich. Könnte mir bitte jemand den Weg zeigen?Wie zeige ich Text im Nachrichtenfeld in verschiedenen Zeilen an?

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






    } 
+1

[Setzen Sie ein '\ n '] (http://stackoverflow.com/questions/1015766/difference-between-n-and-environment-newline) drin? – GolezTrol

Antwort

2

angezeigte dies beinhaltet nicht eine neue Zeile:

"Total Monies Taken is €" + TotalMoniesTaken 

Aber das tut:

"Total Monies Taken is €" + TotalMoniesTaken + Environment.NewLine 
0

hinzufügen Zeilenumbrüche zu jedem:

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

.. usw.

0

Es gibt ein paar Möglichkeiten, wie Sie diese in C# tun, erstens Sie Zeilenumbrüche in der Zeichenfolge

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

Alternativ können Sie verwenden 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); 
0

nur \ n an die verwenden könnte Ende jeder Zeile

MessageBox.Show("test1 \n test2 \n test3"); 
0

Sie zwei Arten tun:

1. ein mit \ n:

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

2. Art und Weise mit Environment.NewLine:

Eg:string msg = "Text " + Environment.NewLine + "with two lines"; 
0

Einige der neueren C# -Funktionen (nicht getestet) MessageBox.Show( [email protected]"Total Monies Taken is €{TotalMoniesTaken} Total Number of Bookings = {TotalGuests} ...");

Verwandte Themen