开发者

Mixed LTR and RTL text in a TextBox control

开发者 https://www.devze.com 2023-04-11 22:52 出处:网络
I have a plain TextBox control in my WinForm application, and I type a string with mixed English and Farsi t开发者_开发技巧ext (mix of LTR and RTL). When the TextBox RightToLeft property is set to Yes

I have a plain TextBox control in my WinForm application, and I type a string with mixed English and Farsi t开发者_开发技巧ext (mix of LTR and RTL). When the TextBox RightToLeft property is set to Yes, it works fine on UI as expected, but when I get the Text property of the TextBox, the string is not what the control shows, and is completely different/wrong.

Here's a screenshot of how the text looks inside the Textbox control (right) and what the Text property returns (shown in a MessageBox).

Mixed LTR and RTL text in a TextBox control

How can I fix this? I expect Text property to return the same thing that is displayed on the UI.


You could pass MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign to the options argument of MessageBox.Show to have the message box both align its text right and also render the entire message box with its text right-to-left:

MessageBox.Show("تست English-mixed جمله ...",
                "عنوان Title",
                MessageBoxButtons.OK,
                MessageBoxIcon.None,
                MessageBoxDefaultButton.Button1,
                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);

Result:

Mixed LTR and RTL text in a TextBox control

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号