如何显示超过63个字符的系统托盘工具提示?

Csu*_*enő 17 c# systray winforms

如何显示超过63个字符的系统托盘工具提示?NotifyIcon.Text有63个字符限制,但我已经看到VNC服务器有更长的工具提示.

我该怎么做VNC服务器呢?

Han*_*ant 28

实际上,它是Text属性的属性设置器中的错误.Windows窗体中的NOTIFYICONDATA的P/Invoke声明使用128个字符限制.你可以用反射破解它:

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 });
      }
    }
Run Code Online (Sandbox Code Playgroud)


bk1*_*k1e 8

从Win32 NOTIFYICONDATA结构上的MSDN文档:

szTip

以null结尾的字符串,用于指定标准ToolTip的文本.它最多可包含64个字符,包括终止空字符.

对于Windows 2000(Shell32.dll版本5.0)及更高版本,szTip最多可包含128个字符,包括终止空字符.

看起来Windows窗体库支持这里最低的公分母.