2009-06-19 53 views
2

我們有一個MDI表單,其中包含一些具有不同標題的子表單,其中顯示當前加載的文檔的文件名。當子窗體被最大化時,他們的標題文本被放置在父窗口的標題欄中,這經常導致文本太長而不能適應欄,並且Windows足夠好以添加省略號和截斷文本。修改或隱藏表單的標題工具提示

但是,當您將鼠標懸停在主窗口的標題欄上時,它會顯示一個工具提示,該提示應該是整個字符串,而工具提示通常包含一小部分字符串。例如,如果主窗體的文本是:

Program1 - Filename:[Really_long_filename_that_doesnt_fit.file]

這將顯示爲工具提示如下:

Program1 - Filename:[Really_long_filename_t

編輯:它總是會截斷提示正好100個字符,這使我相信這是某個地方指定的某個上限。

有沒有辦法改變這個,所以它顯示整個字符串,或者如果沒有,完全禁用工具提示?

任何語言都可以接受,儘管我們在C#中這樣做。

+0

究竟你是什麼懸停在上面嗎?它是任務欄條目還是父級mdi表單的頂部欄? – jjxtra 2009-06-19 17:17:56

+0

父級MDI表單的標題欄您可以通過調整任何形式的大小來複制該行爲,以便標題文本被截斷,然後將鼠標懸停在標題欄上這似乎不重要,但客戶注意到它,現在它是一個問題:P – 2009-06-19 17:19:37

+0

你在XP上運行這個嗎?在Vista中,我沒有得到一個工具提示 – jjxtra 2009-06-19 17:20:44

回答

3

這將使用手動工具提示和計時器顯示/隱藏標題當鼠標移動到標題欄上。

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; 
     }; 
    } 
} 
0

我希望我對你有更多的幫助,但不幸的是,我不認爲有這個辦法。您既可以縮短您的文件名或有對付它:(