Programming Newbie
Programming Newbie

Reputation: 1227

Output text in text box not multi-line, word wrap set to true in text box property

I need the text box to my winform to be multi-line but I can't figure out how to do it. It just comes out as one line. Word wrap is set to true. Do I also have to set it to true within my code? Have I screwed up my formatting somehow? I'm not sure what I am doing wrong. Here is the code:

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

Upvotes: 0

Views: 2159

Answers (2)

joshuahealy
joshuahealy

Reputation: 3569

In windows you need both a carriage return \r and a line feed \n to get a newline. So in your example above you would need to change every \n into a \r\n.

Also, you may not have set the Multiline property.

Upvotes: 2

Derek Harrington
Derek Harrington

Reputation: 467

Try using a RichTextBox instead of a Textbox

Upvotes: 1

Related Questions