我怎么能显示系统托盘提示超过63个字符长? [英] How can I show a systray tooltip longer than 63 chars?

查看:203
本文介绍了我怎么能显示系统托盘提示超过63个字符长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能显示系统托盘提示超过63个字符长? NotifyIcon.Text有63个字符的限制,但我已经看到了VNC服务器有一个较长的提示。

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.

我怎么可以做什么VNC服务器呢?

How can I do what VNC Server does?

推荐答案

其实,它在属性setter Text属性的错误。在P / Invoke的Windows窗体里面声明NOTIFYICONDATA使用128字符的限制。你可以围绕它破解与反思:

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 });
      }
    }

这篇关于我怎么能显示系统托盘提示超过63个字符长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆