문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

This should work for you

string somestring = @"this is some text \n Some more text";
somestring = somestring.Replace(@"\n", Environment.NewLine);
MessageBox.Show(somestring);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top