文本框中的输出文本不是多行,文本框属性中的自动换行设置为true

时间:2012-03-05 02:22:25

标签: c# winforms

我需要将winform的文本框设置为多行,但我无法弄清楚如何做到这一点。它只是作为一条线出来。自动换行设置为true。我是否还必须在我的代码中将其设置为true?我以某种方式搞砸了我的格式吗?我不确定我做错了什么。这是代码:

public override string  ToString()
    {
        return string.Format("{0} Pizzas @ {1:C}: {2:C}\n" +
            "{3} Cokes @ {4:C}  {5:C}\n" +
            "Order Amount: {6:C}\n" +
            "Sales Tax: {7:C}\n" +
            "Amount Due: {8:C}\n" +
            "Amount Paid: {9:C}\n" +
            "Change Due: {10:C}", numberOfPizzas, PIZZA_PRICE, 
            totalCostOfPizza, numberOfCokes, COKE_PRICE, totalCostOfCoke,
            foodAndDrinkTotal, totalSalesTax, totalAmountDue, amountPaid, 
            changeDue);
    }        

........

private void btnPaymentButton_Click(object sender, EventArgs e)
    {            
        amountPaid = double.Parse(this.txtAmountPaid.Text);

        orderPaymentObject = new Payment(orderObject.TotalAmountDue, amountPaid);

        this.txtNumberOfPizzaOrdered.Clear();
        this.txtNumberOfCokesOrdered.Clear();
        this.txtAmountDue.Clear();
        this.txtAmountPaid.Clear();

        this.lblYourOrder.Visible = true;
        this.txtYourOrder.Visible = true;

        this.txtYourOrder.Text =  orderObject.ToString();               
    }     

2 个答案:

答案 0 :(得分:2)

在Windows中,您需要回车符\ r和换行符\ n才能获得换行符。因此,在上面的示例中,您需要将每个\ n更改为\ r \ n。

此外,您可能没有设置Multiline属性。

答案 1 :(得分:1)

尝试使用RichTextBox而不是文本框