Pergunta

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?

Foi útil?

Solução 2

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.

Outras dicas

This should work for you

string somestring = @"this is some text \n Some more text";
somestring = somestring.Replace(@"\n", Environment.NewLine);
MessageBox.Show(somestring);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top