How can I show a systray tooltip longer than 63 chars?

后端 未结 5 731
不知归路
不知归路 2021-02-02 12:48

How can I show a systray tooltip longer than 63 chars? NotifyIcon.Text has a 63 chars limit, but I\'ve seen that VNC Server has a longer tooltip.

How can I do what VNC S

5条回答
  •  醉话见心
    2021-02-02 13:17

    Actually, it is a bug in the property setter for the Text property. The P/Invoke declaration for NOTIFYICONDATA inside Windows Forms uses the 128 char limit. You can hack around it with Reflection:

    using System;
    using System.Windows.Forms;
    using System.Reflection;
    
        public class Fixes {
          public static void SetNotifyIconText(NotifyIcon ni, string text) {
            if (text.Length >= 128) throw new ArgumentOutOfRangeException("Text limited to 127 characters");
            Type t = typeof(NotifyIcon);
            BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance;
            t.GetField("text", hidden).SetValue(ni, text);
            if ((bool)t.GetField("added", hidden).GetValue(ni))
              t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true });
          }
        }
    

提交回复
热议问题