how to wordwrap text in tooltip

前端 未结 5 2063
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 17:45

How to wordwrap text that need to be appear in ToolTip

5条回答
  •  一向
    一向 (楼主)
    2021-01-11 18:08

    It looks like it isn't supported directly:

    How do I word-wrap the Tooltip that is displayed?

    Here is a method using Reflection to achieve this.

    [ 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; 
    private const uint TTM_SETMAXTIPWIDTH = 0x418;
    SendMessage( hwnd, TTM_SETMAXTIPWIDTH, 0, 300 );
    

    Rhett Gong

提交回复
热议问题