2016-09-16 19 views
0

我正在嘗試創建多行工具提示。我正在嘗試做多行工具提示。 Linebreaking charachters does't working

myToolTip.ToolTipTitle="First line\nSecond line"; 
myToolTip.ToolTipTitle="First line\r\nSecond line"; 
myToolTip.ToolTipTitle="First line\nSecond line"; 
string s="First line\nSecond line"; 
s = s.Replace("\n", Environment.NewLine); 
myToolTip.ToolTipTitle=s; 

所有上面的代碼只顯示ONELINE提示,並始終低於增加額外的行: enter image description here 我試着在ToolTipTitle串線斷線charachters插入諸如「\ r \ n」「\ n」或環境。 Newline,但它仍然不起作用。有什麼建議麼?

回答

-1

沒有足夠的JavaScript代碼來解決您的問題。如果您使用的是彈出式提醒(),那麼「\ n \ n」將起作用;我一直這麼做。

這是一種解決方法:使用HTML5標題屬性並對換行符進行硬編碼。就像這樣:

0

的ToolTipTitle不能有多個行,但標題可以。

試試這樣說:

StringBuilder sb = new StringBuilder(); 
sb.AppendLine("First Line"); 
sb.AppendLine("Second Line"); 
myToolTip.SetToolTip(button1, sb.ToString()); 

myToolTip.Show(sb.ToString(), button1); 
+0

謝謝@LarsTech。我找到了解決方案,並通過工作示例添加了我自己的答案。 – Alexander

+0

@Alexander這不是我的答案嗎? – LarsTech

+0

是的,它很多,但我提供了完整的工作示例。此外,我認爲使用符號「\ n」打破字符串是最短的方式。當用戶將鼠標移動到PictureBox上時,我也遇到了閃爍問題。這也得到了解決。 – Alexander

0

我發現,部分基於@Shimmy's答案的問題Displaying tooltip on mouse hover of a text分辨率。我不得不使用toolTip1.SetToolTip(pictureBox1,TextString)函數。工具提示標題不能是多行。

需要定時器來避免閃爍。當用戶將鼠標移到PictureBox上時,工具提示顯示多行文本。

public partial class Form1 : Form 
{ 
    private System.Windows.Forms.ToolTip toolTip1; 
    private System.Windows.Forms.PictureBox pictureBox1; 
    System.Windows.Forms.Timer ToolTipsTimer = new System.Windows.Forms.Timer(); 
    public Form1() 
    { 
     InitializeComponent(); 

     ToolTipsTimer.Tick += new EventHandler(ToolTipsTimerEventProcessor); 
     ToolTipsTimer.Interval = 300; 
     ToolTipsTimer.Start(); 
     toolTip1.AutomaticDelay = 300; 

    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 

    } 
    private void ToolTipsTimerEventProcessor(Object myObject, EventArgs myEventArgs) 
    { 
     ToolTipsTimer.Enabled = false; 
    } 

    string TextString = "First line\n Second line"; 
    private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (!ToolTipsTimer.Enabled) 
     { 
      toolTip1.SetToolTip(pictureBox1, TextString); 
      ToolTipsTimer.Enabled = true; 
     } 
    } 
} 
+0

當你用[另一個答案](http://stackoverflow.com/a/39534999/3110834)的幫助來回答你自己的問題時,一個好方法是提高你用來解決問題的答案:) –