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

后端 未结 5 740
不知归路
不知归路 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:19

    I recently came across a similar problem. Rather than hacking the back-end, I implemented a work-around, which makes use of the BalloonTipText, which can accommodate quite a lot of characters.

    The tooltip is shown on the first MouseMove event over the tray icon and the tooltip is displayed for 2 seconds. Atter the tooltip is closed, it can be re-opened again by a new MouseMove event.

    The only downside with this solution is that is is not possible to close the balloon programatically, when a user, say, leaves the icon area, so it only disappears after a timeout or if the user clicks on the small X-button.

    Note that the title and the text can be set at any time elsewhere in the program. They are set here in the event for demonstration purpose only.

    EDIT: ShowBalloonTip() fires addition cascading MouseMove events, so it is necessary to disable this event until such time as the balloon tooltip is hidden. Additionally, BalloonTipClosed is (according to the documentation) only fired when the user actively clicks on 'X', though I observed it being fired when the tooltip closed after a timeout. I therefore added a helper timer to reset the sate, instead of relying on the BalloonTipClosed event. The revised and tested code is below:

        private bool balloonTipShown;
        private Timer balloonTimer;
        private void trayIcon_MouseMove(object sender, MouseEventArgs e)
        {
            if (balloonTipShown)
            {
                return;
            }
            balloonTipShown = true;
            trayIcon.MouseMove -= trayIcon_MouseMove;
            balloonTimer = new Timer();
            balloonTimer.Tick += balloonTimer_Tick;
            balloonTimer.Interval = 2005;
            balloonTimer.Start();
            trayIcon.ShowBalloonTip(2000);
        }
    
        void balloonTimer_Tick(object sender, EventArgs e)
        {
            balloonTipShown = false;
            balloonTimer.Stop();
            balloonTimer.Dispose();
            trayIcon.MouseMove += trayIcon_MouseMove;
        }
    

    EDIT 2: A screenshot of a balloon tooltip with quite a lot of text, that utilises this solution can be seen in by blog.

提交回复
热议问题