我们有一个MDI表单,其中包含一些子表单,这些表单具有不同的标题,显示当前加载的文档的文件名。当子窗体最大化时,它们的标题文本将被放置在父窗口的标题栏中,这通常会导致文本太长而无法放入栏中,而Windows足以添加省略号并截断文本。

但是,当您将鼠标悬停在主窗口的标题栏上时,它会显示一个工具提示,其中应包含整个字符串,但工具提示通常只包含字符串的一小部分。例如,如果主表单的文本是:

Program1 - Filename:[Really_long_filename_that_doesnt_fit.file]

它将在工具提示中显示如下:

Program1 - Filename:[Really_long_filename_t

编辑:它总是将工具提示截断为正好100个字符,这使我相信它是在某处指定的某个上限。

是否有办法更改此设置以显示整个字符串,如果没有,则完全禁用工具提示?

任何语言都是可以接受的,尽管我们在C#中这样做。

有帮助吗?

解决方案

当鼠标在标题栏上移动时,它使用手动工具提示和计时器显示/隐藏标题。

public partial class Form1 : Form
{
    private ToolTip toolTip = new ToolTip();
    private Timer toolTipTimer = new Timer();
    private bool canShowToolTip = true;

    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case 0x2A0: // WM_NCMOUSEHOVER
                return;
            case (int)0x00A0: // WM_NCMOUSEMOVE
                if (m.WParam == new IntPtr(0x0002)) // HT_CAPTION
                {
                    if (canShowToolTip)
                    {
                        canShowToolTip = false;
                        toolTip.Show(this.Text, this, this.PointToClient(Cursor.Position), toolTip.AutoPopDelay);
                        toolTipTimer.Start();
                    }
                }
                return;
        }
        base.WndProc(ref m);
    }

    public Form1()
    {
        InitializeComponent();
        Form child = new Form();
        child.Text = "Program1 - Filename:[Really_long_filename_that_doesnt_fit.file] AAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
        child.MdiParent = this;
        child.Show();
        toolTip.AutoPopDelay = 5000;
        toolTipTimer.Interval = toolTip.AutoPopDelay;
        toolTipTimer.Tick += delegate(object sender, EventArgs e)
        {
            canShowToolTip = true;
        };
    }
}

其他提示

我希望我能为你提供更多帮助,但不幸的是,我认为没有办法解决这个问题。您可以缩短文件名或者必须处理它:(

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top