2016-11-21 8 views
-1

それぞれの合計をボックス内の別の行に表示したいが、現時点ではそれは重複している。 誰かが私に方法を教えてもらえますか?メッセージボックスのテキストを異なる行に表示する方法は?

これは新しい行は含まれません表示
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

[ '\ nを入れて'](http://stackoverflow.com/questions/1015766/difference-between-n-and-environment-newline)そこに? – GolezTrol

答えて

2

"Total Monies Taken is €" + TotalMoniesTaken 

をしかし、これはない:

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

がそれぞれに改行を追加します。

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

.. etc

0

はあなただけ\ nでの使用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

を使用することができ、まずあなたが

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

また、あなたの文字列に改行を使用することができ、あなたがC#でこれを行うことができますいくつかの方法があります次の2つの方法を行うことができます

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

各行の終わり:

第一\ nは1:Environment.NewLineと

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

第二の方法:

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

新しいC#の機能の一部(テストしていない) MessageBox.Show( [email protected]"Total Monies Taken is €{TotalMoniesTaken} Total Number of Bookings = {TotalGuests} ...");

関連する問題