Right to left tooltip text 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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从右到左的工具提示文本c#
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
