如何在不同行的消息框中显示文本?

时间:2016-11-21 15:52:29

标签: c#

我希望每个Total显示在框中的不同行上,但此刻它会保持重叠。 有人可以给我指路吗?

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






    }

6 个答案:

答案 0 :(得分:3)

显示此内容不包括新行:

"Total Monies Taken is €" + TotalMoniesTaken

但这样做:

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

答案 1 :(得分:0)

为每一个添加换行符:

java.sql.Statement.setPoolable(false)

...等

答案 2 :(得分:0)

有几种方法可以在C#中执行此操作,首先您可以在字符串中使用换行符

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

或者,您可以使用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);

答案 3 :(得分:0)

在每行末尾使用\ n

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

答案 4 :(得分:0)

您可以采用以下两种方式:

第一个用\ n:

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

使用Environment.NewLine的第二种方式:

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

答案 5 :(得分:0)

一些较新的C#功能(未经测试) MessageBox.Show( $@"Total Monies Taken is €{TotalMoniesTaken} Total Number of Bookings = {TotalGuests} ...");

相关问题