MysticalGoat
MysticalGoat

Reputation: 1

Using Windows forms c# message box

How will I get a messagebox "Or another way of doing this" to have multiple lines? I've got a messageBox to appear when the user presses F1 and I need it to have a sort of list:

Product Name = Alphanumeric + Special Characters.
Quantity = Maximum 100.
Price = Must be Numeric.

Etc Thanks.

Upvotes: 0

Views: 4218

Answers (4)

Abbas
Abbas

Reputation: 14432

You can use \r\n or Environment.NewLine at the end of each line to be shown or you can use the StringBuilder class:

    var message = new StringBuilder();
    message.AppendLine("Product Name = Alphanumeric + Special Characters.");
    message.AppendLine("Quantity = Maximum 100.");
    message.AppendLine("Price = Must be Numeric.");
    MessageBox.Show(message.ToString());

Upvotes: 4

Allan Elder
Allan Elder

Reputation: 4104

Put "\r\n" at the end of each line of the message.

so, for example:

        var message = "Product Name = MyProduct.\r\n";
        message += "Quantity = Maximum 100.\r\n";
        message += "Price = Must be Numeric.\r\n";

        MessageBox.Show(message);

Upvotes: 2

musefan
musefan

Reputation: 48435

Just use Environment.NewLine where you want a newline to appear. For example:

string message = "Line 1" + Environment.NewLine + "Line 2";
MessageBox.Show(message);

This will output:

Line 1
Line 2

Upvotes: 1

David Osborne
David Osborne

Reputation: 6821

Add/concatenate Environment.Newline to your string.

Upvotes: 3

Related Questions