问题描述
在表单上,表单的标题是设计器文件中设置的文本.我遇到的问题是,当标题国际化时,标题会缩短并添加省略号.是否可以添加当我们将鼠标悬停在标题上时会显示的工具提示?因此,如果我将鼠标悬停在Form1"上,工具提示应显示Form1".
表单是用 C# 编写的.由于标题不是表单中的控件,所以无法设置tooltip.
有什么想法吗?
此外,有关处理 MDI 子表单的相关问题的更复杂方法,请参阅 Reza Aghaei 的这篇帖子,他现在也通过重构实现回答了这个问题.
On a Form, the title of the form is the Text that is set in the Designer file. The problem I am having is that when the title is internationalized, the title gets shortened and an ellipsis is added. Is it possible to add a tooltip that will display when we hover over the title? So if I am hovering over "Form1", a tooltip should display that says "Form1".
Form is written in C#. Since the title is not a control in the form, I can't set the tooltip.
Any ideas?
One approach would be to do this:
using System.Drawing;
using System.Threading.Tasks;
public Form1()
{
InitializeComponent();
ImplementToolBarToolTip();
}
private readonly ToolTip _toolTip1 = new ToolTip();
private async void ImplementToolBarToolTip()
{
while (!IsDisposed)
{
await Task.Delay(200);
var right = Left + Width;
var bottom = Top + 39;
var x = Cursor.Position.X;
var y = Cursor.Position.Y;
if (IsDisposed) return;
if (x > Left && x < right && y > Top && y < bottom)
{
_toolTip1.Show(Text, this, PointToClient(new Point(x, y)));
}
else _toolTip1.Hide(this);
}
}
Note: If you would prefer not to show the tooltip when the user mouses over the Close, Minimize, or Maximise buttons on the far right, then subtract 149 from the right
value:
var right = Left + Width - 149;
Also, for a more sophisticated approach to a related problem dealing with MDI child forms, see This post by Reza Aghaei, who has now also replied to this question with a refactored implementation.
这篇关于可以向表单标题添加工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!