如何显示长度超过 63 个字符的系统托盘工具提示? NotifyIcon.Text 有 63 个字符的限制,但我发现 VNC Server 有更长的工具提示。
我怎样才能完成 VNC Server 所做的事情?
实际上,这是 Text 属性的属性设置器中的一个错误。 Windows 窗体内 NOTIFYICONDATA 的 P/Invoke 声明使用 128 个字符的限制。你可以用 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 });
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)