简体   繁体   中英

MessageBox Text from Settings

I would like to set my WinForm controls' text from the Settings.

In case I would like to change in the future the program language, it is quite easy;

Just have to modify the appropriate settings.

One of the messageBoxes text has a line break ( \\n ).
When I insert its text from Settings, the \\n appears as part of the text and there is no line- break.

MessageBox.Show(P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotification, 
P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotificationTitle, 
MessageBoxButtons.YesNo, MessageBoxIcon.Question);

Any ideas?

This should work for you

string somestring = @"this is some text \n Some more text";
somestring = somestring.Replace(@"\n", Environment.NewLine);
MessageBox.Show(somestring);

Replace:

MessageBox.Show(P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotification, 
P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotificationTitle, 
MessageBoxButtons.YesNo, MessageBoxIcon.Question);

With:

MessageBox.Show(P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotification.Replace(@"\n", Environment.NewLine)), 
P_Settings.NotificationMessageBoxes.Default.ProcessFinishedNotificationTitle, 
MessageBoxButtons.YesNo, MessageBoxIcon.Question);

Replace will check for \\n and replaces it with: Environment.NewLine . The Escape sequences have no meaning within actual string objects. Only when the C# compiler interprets them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM