如何換行需要被顯示在工具提示如何換行的提示
Q
如何換行的提示
10
A
回答
7
看起來它不直接支持文本文字:
如何換行的工具提示被展示?
這裏是一個使用Reflection的方法,以 實現這個。
[ DllImport("user32.dll") ] private extern static int SendMessage(IntPtr hwnd, uint msg, int wParam, int lParam); object o = typeof(ToolTip).InvokeMember("Handle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, myToolTip, null); IntPtr hwnd = (IntPtr) o; SendMessage(hwnd, 0x0418, 0, 300);
瑞德宮
5
+3
這看起來像一個PHP代碼或什麼的。這裏的C#版本: 正則表達式rgx = new Regex(「(。{50} \\ s)」); string WrappedMessage = rgx.Replace(longMessage,「$ 1 \ n」); – Patratacus 2013-08-02 01:22:55
1
這一塊我最近寫了,我知道它不是最好的,但它的工作原理。你需要如下擴展工具提示控件:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
public class CToolTip : ToolTip
{
protected Int32 LengthWrap { get; private set; }
protected Control Parent { get; private set; }
public CToolTip(Control parent, int length)
: base()
{
this.Parent = parent;
this.LengthWrap = length;
}
public String finalText = "";
public void Text(string text)
{
var tText = text.Split(' ');
string rText = "";
for (int i = 0; i < tText.Length; i++)
{
if (rText.Length < LengthWrap)
{
rText += tText[i] + " ";
}
else
{
finalText += rText + "\n";
rText = tText[i] + " ";
}
if (tText.Length == i+1)
{
finalText += rText;
}
}
}
base.SetToolTip(Parent, finalText);
}
}
你會使用它像:
CToolTip info = new CToolTip(Control,LengthWrap);
info.Text("It looks like it isn't supported directly. There is a workaround at
http://windowsclient.net/blogs/faqs/archive/2006/05/26/how-do-i-word-wrap-the-
tooltip-that- is-displayed.aspx:");
0
可以使用e.ToolTipSize
屬性設置工具提示的大小,這將迫使自動換行:
public class CustomToolTip : ToolTip
{
public CustomToolTip() : base()
{
this.Popup += new PopupEventHandler(this.OnPopup);
}
private void OnPopup(object sender, PopupEventArgs e)
{
// Set custom size of the tooltip
e.ToolTipSize = new Size(200, 100);
}
}
1
對於WPF,您可以使用TextWrapping屬性:
<ToolTip>
<TextBlock Width="200" TextWrapping="Wrap" Text="Some text" />
</ToolTip>
相關問題
- 1. 如何將單行換行提示AutoCompleteTextView?
- 2. GWT代碼 - 如何用換行強制提示工具提示?
- 3. hint.css手動換行提示
- 4. 如何添加服裝工具提示上的換行符?
- 5. 如何從命令提示符發送EOF *不帶換行符*?
- 6. 如何在userform鼠標懸停工具提示上換行符?
- 7. 如何在工具提示中獲取換行符
- 8. 圖JS V2提示回調換行符
- 9. Bash提示符換行問題
- 10. 如何退出Zend命令行提示
- 11. 如何進行強制性提示
- 12. 提示Webkit轉換
- 13. 如何提示提醒?
- 14. 將行換行添加到Bootstrap中的工具提示3
- 15. 如何打開Silverlight 4中所有工具提示的文字換行?
- 16. 在java中,如何將換行符添加到JButton的工具提示?
- 17. 如何在Flex中顯示mx Datagrid行中的工具提示?
- 18. 如何在運行時爲VBA顯示UDF的工具提示?
- 19. 如果提示變化,如何登錄以切換和執行命令?
- 20. 如何使Html.DisplayFor顯示換行符?
- 21. 如何在jTemplate中顯示換行符
- 22. 如何使用outputText顯示換行符?
- 23. 如何切換表格行顯示?
- 24. 如何從提示
- 25. 如何不提示
- 26. 如何從提示
- 27. 如何在提示jQuery的
- 28. 如何qtip提示的jQuery
- 29. 如何替換Fly上的工具提示數組值?
- 30. 如何顯示禁用TDBEdit的提示?
嗨,這個代碼放在哪裏? – 2011-01-25 05:11:27
理想情況下,此處的幻數0x418應該定義爲與相應頭文件Commctrl.h中使用的名稱相同的常量:「private const uint TTM_SETMAXTIPWIDTH = 0x418」 - 這使得Google可以更容易地獲取更多信息。 – Joe 2011-04-01 12:03:27
在Windows 7中,我體驗到這種破解只能解決OS在OS中禁用視覺樣式時的問題。任何想法如何解決這種情況? – Mustafa 2011-09-23 09:38:33