Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a string displayed in a MessageBox in C#?

Tags:

string

c#

.net

wpf

I want to display a string in a message box with a following format:

Machine : TestMachine User : UserName

I am doing this:

string strMsg = "Machine  :" + "TestMahine" + "\r\n" +
                "User     :" + "UserName";

MessageBox.Show(strMsg);

When I do this the message box do not display a string as formated above. Colon(") dosen't keep alligned. The above format is also do not work in WPF TextBlock control.

Please help!!

like image 333
Arvind Bhatt Avatar asked Dec 09 '22 13:12

Arvind Bhatt


1 Answers

Try something like this:

string strMsg = String.Format("Machine\t: {0}\nUser\t: {1}", "TestMachine", "UserName");

Edited: Gotta have that String.Format there or that lone bracket at the end is sad.

like image 142
JonVD Avatar answered Dec 14 '22 22:12

JonVD