Reputation: 35
I set the TextBox.RightToLeft
property to Yes
.
When I'm entering this text: "a 32" the string that is stored
is "32 a".
the order of entering the text is: first 32 then Space and thena.
How can I have the value stored as entered?
Upvotes: 2
Views: 1624
Reputation: 125257
OP: How can I have the value stored as entered?
The string will be stored exactly in the same order you entered characters regardless of display settings of TextBox
.
If you enter 32Spacea then your values will be stored in the same order and the value of Text
property of TextBox
will be 32 a
while it will be displayed different based on RightToLeft
and TextAlign
property.
Here is the result of entering the text in the order: 32Spacea.
Choose your desired setting, store the string and then show it again in a TextBox
with the same settings.
Upvotes: 0
Reputation: 12449
If the value of the RightToLeft property is changed at run time, only raw text without formatting is preserved.
You will have to reverse its order yourself:
string[] text = textBox1.Text.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); //get string while preserving the words
Array.Reverse(text); //reverse the order of words (not their chars)
string finalValue = string.Join(" ", text); //make the string out of array
Upvotes: 0
Reputation: 724
Try this:
Set your TextBox Property RightToLeft = NO and use TextAlign = Right.
Upvotes: 2