C# ListView and RightToLeft

2019-08-06 02:13发布

问题:

I need to view english text in a listview with the RightToLeft property set to "true".
When I put brackets in the text it seems to be reversed.
If I try to write "Stack(Overflow)" I will see "(Stack(Overflow".
Is there a way to fix this?

this is a part of my code:

                    Item = (ListViewItem) myList.Items.Add(id, myString, iconIndex);
                    MyListView.SetSubItemText(Item, 1, s1);
                    MyListView.SetSubItemText(Item, 2, s2);
                    MyListView.SetSubItemText(Item, 3, s3);
                    MyListView.SetSubItemText(Item, 4, s4);

回答1:

This strongly depends on the version of Windows you use, list view is implemented as a native control in Windows, the ListView class is only a managed wrapper for it. The right-to-left rendering behavior has changed across different versions.

In general, you should only ever set RightToLeft to Yes when you localized your user interface to a language that requires right-to-left rendering of text. Hebrew or Arabic. Getting unusual behavior with strings in another language is not unexpected. If your intent was to get different alignment using that property then you'll have to find an alternative. Like OwnerDraw or ColumnHeader.TextAlign