1

See below the Testo textbox has the Full Stop correctly at the beginning: enter image description here

In the Watch Window and in memory string variables the FullStop is incorrectly at the End: enter image description here

The result of this is when I graphically process the string the Full Stop (aka dot) is in the wrong position, how should I move it at start?

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
IssamTP
  • 2,408
  • 1
  • 25
  • 48

1 Answers1

1

You can use Visual Studio to create Windows-based applications that support bi-directional (right-to-left) languages such as Arabic and Hebrew, you will need to set the Control.RightToLeft Property

Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.

Both of these answers failed but helped identify the solution.

If you want to get the RTL value in code with variables you have to rely on the unicode control characters to mark them as RTL.

var badWhenSetRTLtrue = textBox1.Text;
var goodWhenSetRTLtrue = ((Char)0x202B).ToString() + textBox1.Text;

It would make sense to have these as Extension methods:

partial class StringExtensions {

private const char LTR_EMBED = '\u202A';
private const char RTL_EMBED = '\u0x202B';
private const char POP_DIRECTIONAL = '\u202C';
private string ForceLTR(this string inputStr)
{
    return LTR_EMBED + inputStr + POP_DIRECTIONAL;
}

private string ForceRTL(this string inputStr)
{
    return RTL_EMBED  + inputStr;
}

}

eg:

textBox1.Text.ForceRTL();

For anyone wanting to do this with a web browser and HTML (instead of WinForms) you can set the direction: rtl;, eg:

<p style="direction: rtl;">טקסט</p>

Or either of these answers: https://stackoverflow.com/a/42551367/495455

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • "the RTL property is set to true as soon as they select, for instance, a font with arabic script." ... – IssamTP Jul 13 '20 at 07:08
  • Yes, as I said: the layout of the text box is correctly updated (figure 1), my problem is that the in memory string keeps the dot in wrong position (figure 2). – IssamTP Jul 13 '20 at 07:14
  • Well, that's it, but I still have another problem: if I request for the first char, I got the last instead of the first (I got م instead of .). – IssamTP Jul 13 '20 at 08:50