从右到左的文字提示C# [英] Right to left tooltip text c#
问题描述
使用的WinForms,我有我想设置成一个工具提示字符串。该字符串由线与 Environment.NewLine
分离,像这样:
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
不过,我的问题是,当我希望它被定位于阿拉伯语和工具提示不支持默认RightToLeft属性,所以看起来非常糟糕。我希望它看起来像:
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
另外: String.PadLeft
无助
任何想法?
推荐答案
第二个尝试。没能得到以前的解决方案试图正常运行。 。发现通过使用自定义绘制方法绘制工具提示的另一种方法。
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.
安装的控件:
string tip = "aaaaaa" + Environment.NewLine + "bbb";
toolTip1.OwnerDraw = true;
toolTip1.Draw += toolTip1_Draw;
toolTip1.SetToolTip(textBox1, tip);
办理抽奖活动:
Handle the draw event:
private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.Info, e.Bounds);
e.DrawBorder();
e.DrawText(TextFormatFlags.RightToLeft | TextFormatFlags.Right);
}
这篇关于从右到左的文字提示C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!