5

When adding a ToolStripMenuItem to a form and setting RightToLeft to true and having a quote at the end of the text does it place the quote at the front of the Text?

ToolStripMenuItem1.Text = "Name \"Text\"";
ToolStripMenuItem1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;

Displays as; "Name "Text

Edit: This also happens with single quotes.

ManicResin
  • 59
  • 3

2 Answers2

4

By setting RightToLeft to Yes, you are asking the Windows text rendering engine to apply the text layout rules used in languages that use a right-to-left order. Arabic and Hebrew. Those rules are pretty subtle, especially because English phrases in those languages are not uncommon. It is not going to render "txeT emaN" as it normally does with Arabic or Hebrew glyphs, that doesn't make sense to anybody. It needs to identify sentences or phrases and reverse those. Quotes are special, they delineate a phrase.

Long story short, you are ab-using a feature to get alignment that was really meant to do something far more involved. Don't use it for that.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    Also note the bit of masterful API design. It is not a bool property, you don't set it to true. It is an enum with only two legal values, Yes and No. Pointing out: hey, this is not just a simple option. Awesome. – Hans Passant Aug 20 '11 at 23:07
  • That may be but it appears to be happening with most punctuation characters and other symbols. So if this is the cause how would one properly display this form control to appear right to left without causing this? EDIT: I fixed the mistake in my questions code. – ManicResin Aug 20 '11 at 23:09
  • 1
    Yes, punctuation also delineates phrases. Try to re-read the answer and pick a part that isn't clear to you, I don't understand why you posted the comment. The essence of the answer is that RightToLeft is meant to do something *completely* different than what you want to use it for. Text alignment is only a small side effect of it. – Hans Passant Aug 20 '11 at 23:12
  • How about this, since I don't quite understand the localization of text translations what other way is there to get the menu items to display right to left with out setting the text property? – ManicResin Aug 20 '11 at 23:23
  • 1
    ToolStripMenuItem is hard-coded to implement Windows GUI rules. Which is why @yahia's edit doesn't work. It is possible, you'll have to implement your own renderer. Starting point is here: http://stackoverflow.com/questions/1756583/toolstrip-vs-menustrip-can-i-make-their-rendering-identical – Hans Passant Aug 20 '11 at 23:42
0

EDIT:
IF you just want to change Text Alignment then there is always ToolStripItem.Alignment or ToolStripItem.Padding to try...

The feature you are using is meant for localization and can support mixed content... The way you use that feature seems more like an abuse... since Windows needs to make sense of "mixed content" of which you provide an extreme (no arabic at all).

I find it always hard to be sure that such behaviour though unexpected and unintuitive is really a bug...

Rendering logic for BiDi text is rather complex - for example when you have an exclamation mark somewhere in text which should be rendered RightToLeft it can lead to reversing the direction depending on the implementation...

For some insight see http://www.unicode.org/reports/tr9/

As it seems .NET is not fully compliant with the Unicode BiDi algorithm... there is even library that tries to implement it see http://sourceforge.net/projects/nbidi/

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Thanks for the edit that is more towards where I'm headed. I'm actually looking for a way to get the menu items to display from the opposite direction. – ManicResin Aug 20 '11 at 23:35