从右到左的工具提示文本c# [英] Right to left tooltip text c#

查看:23
本文介绍了从右到左的工具提示文本c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 WinForms,我有一个字符串,我想将其设置为 ToolTip.该字符串由 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

但我的问题是当我希望它本地化为阿拉伯语并且 ToolTip 不支持默认的 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);

处理抽奖事件:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆