Using WinForms, I have a string which I want to set into a ToolTip. The string is separated by lines with Environment.NewLine
, like so:
x.ToolTipText = "aaaaaa" + Environment.NewLine + "bbb";
when this string is set to the ToolTip it looks:
aaaaaa
bbb
But my problem is when I want it to be localized to Arabic and ToolTip does not support the default RightToLeft property, so it looks very bad. I want it to look like:
aaaaaa
bbb
Also: String.PadLeft
does not help!
Any idea?
The ToolTip control already supports this. The key is that the control for which you display the tip has a right-to-left layout. This example form demonstrates this:
Just some general thoughts to give an idea about what's going on: the tooltip class does not draw text like a multiline textbox. The whole tool-tip is considered one line without a binding rectangle, hence RTL vs LTR have no meaning (other then the order of characters within the text).
Result: using normal right-to-left or left-to-right switches either with Unicode RTL codepoints or otherwise, won't help when it comes to aligning: none is applied.
One way out is (ab)using a TextBox and place it nicely over the place of the tooltip. But others have shown prettier ways with owner-drawn tooltips, which is definitely the way to go.
Second try. Didn't manage to get the previous solution attempt to behave correctly. Found an alternate way by rendering the tooltip using a custom draw method.
Setup the controls:
Handle the draw event:
If it's windows forms I guess you have to rely on the unicode control characters to mark the tooltip text as RTL.
Check this blog for more information on authoring RTL applications.
If it's a web application you can check the w3c authoring RTL applications guidelines. Basically it comes down to the same solution as for windows forms, adding RLE chars.