从右到左的工具提示文本c#

Right to left tooltip text c#(从右到左的工具提示文本c#)
本文介绍了从右到左的工具提示文本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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)