Ejemplo n.º 1
0
        /// <summary>
        /// Displays a Balloon ToolTip for the current NotifyIcon.
        /// </summary>
        /// <param name="iconStyle">The balloon ToolTip's icon to use. This icon is placed to the 
        /// left of the balloon ToolTip's title.</param>
        /// <param name="text">The text to display for the balloon ToolTip. The length of the text can not
        /// exceed 254 characters.</param>
        /// <param name="title">The text to display as a title for the balloon ToolTip. 
        /// This title appears in boldface above the text. It can have a maximum of 63 characters.
        /// Pass null or String.Empty to prevent the balloon from displaying a title.</param>
        /// <param name="timeout">The number of milliseconds the balloon ToolTip should remain visible
        /// before it is hidden. The system enforces minimum and maximum timeout values. Timeout values that 
        /// are too large are set to the maximum value and values that are too small default to the 
        /// minimum value. The system minimum and maximum timeout values are currently set at 10 seconds 
        /// and 30 seconds, respectively.</param>
        /// <exception cref="ArgumentNullException">Text is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Text is longer than 254 characters.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Title is longer than 254 characters.</exception>
        public void ShowBalloon(BalloonIconStyle iconStyle, string text, 
            string title, int timeout)
        {
            if(null == text)
                throw new ArgumentNullException("Text is not optional.", "text");
            if(null != text && text.Length > MaxBaloonTextLength)
                throw new ArgumentOutOfRangeException("The text is too long. Please provide a string with " +
                    "fewer than 255 characters.", "text");
            if(null == title)
                title = string.Empty;
            if(null != title && title.Length > MaxBaloonTitleLength)
                throw new ArgumentOutOfRangeException("The title is too long. Please provide a string with " +
                    "fewer than 64 characters.", "title");

            _VisibleBeforeBalloon = Visible;

            NOTIFYICONDATA nid;

            nid = new NOTIFYICONDATA();
            nid.uCallbackMessage = Win32.WM_USER_TRAY;
            nid.cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
            nid.uFlags = Win32.NIF_MESSAGE;
            nid.hwnd = this._Messages.Handle;
            nid.uID = 0;

            nid.hIcon = IntPtr.Zero;

            nid.uFlags = nid.uFlags | Win32.NIF_ICON;
            nid.hIcon = this.Icon.Handle;

            nid.uFlags = nid.uFlags | Win32.NIF_INFO;

            // Timeout value is sent in version
            nid.uVersion = timeout;

            nid.szInfo = text;
            nid.szInfoTitle = title;
            nid.dwInfoFlags = Convert.ToInt32(iconStyle);

            // Make sure our Visible property indicates true.
            if(!this.Visible)
                this._Visible = true;

            if (!this._Added)
            {
                Win32.Shell_NotifyIcon(Win32.NIM_ADD, ref nid);
                this._Added = true;
            }
            else if(this._Added)
                Win32.Shell_NotifyIcon(Win32.NIM_MODIFY, ref nid);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Displays a Balloon ToolTip for the current NotifyIcon.
        /// </summary>
        /// <param name="iconStyle">The balloon ToolTip's icon to use. This icon is placed to the
        /// left of the balloon ToolTip's title.</param>
        /// <param name="text">The text to display for the balloon ToolTip. The length of the text can not
        /// exceed 254 characters.</param>
        /// <param name="title">The text to display as a title for the balloon ToolTip.
        /// This title appears in boldface above the text. It can have a maximum of 63 characters.
        /// Pass null or String.Empty to prevent the balloon from displaying a title.</param>
        /// <param name="timeout">The number of milliseconds the balloon ToolTip should remain visible
        /// before it is hidden. The system enforces minimum and maximum timeout values. Timeout values that
        /// are too large are set to the maximum value and values that are too small default to the
        /// minimum value. The system minimum and maximum timeout values are currently set at 10 seconds
        /// and 30 seconds, respectively.</param>
        /// <exception cref="ArgumentNullException">Text is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Text is longer than 254 characters.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Title is longer than 254 characters.</exception>
        public void ShowBalloon(BalloonIconStyle iconStyle, string text,
                                string title, int timeout)
        {
            if (null == text)
            {
                throw new ArgumentNullException("Text is not optional.", "text");
            }
            if (null != text && text.Length > MaxBaloonTextLength)
            {
                throw new ArgumentOutOfRangeException("The text is too long. Please provide a string with " +
                                                      "fewer than 255 characters.", "text");
            }
            if (null == title)
            {
                title = string.Empty;
            }
            if (null != title && title.Length > MaxBaloonTitleLength)
            {
                throw new ArgumentOutOfRangeException("The title is too long. Please provide a string with " +
                                                      "fewer than 64 characters.", "title");
            }


            _VisibleBeforeBalloon = Visible;

            NOTIFYICONDATA nid;

            nid = new NOTIFYICONDATA();
            nid.uCallbackMessage = Win32.WM_USER_TRAY;
            nid.cbSize           = Marshal.SizeOf(typeof(NOTIFYICONDATA));
            nid.uFlags           = Win32.NIF_MESSAGE;
            nid.hwnd             = this._Messages.Handle;
            nid.uID = 0;

            nid.hIcon = IntPtr.Zero;

            nid.uFlags = nid.uFlags | Win32.NIF_ICON;
            nid.hIcon  = this.Icon.Handle;


            nid.uFlags = nid.uFlags | Win32.NIF_INFO;

            // Timeout value is sent in version
            nid.uVersion = timeout;

            nid.szInfo      = text;
            nid.szInfoTitle = title;
            nid.dwInfoFlags = Convert.ToInt32(iconStyle);

            // Make sure our Visible property indicates true.
            if (!this.Visible)
            {
                this._Visible = true;
            }

            if (!this._Added)
            {
                Win32.Shell_NotifyIcon(Win32.NIM_ADD, ref nid);
                this._Added = true;
            }
            else if (this._Added)
            {
                Win32.Shell_NotifyIcon(Win32.NIM_MODIFY, ref nid);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Displays a Balloon ToolTip for the current NotifyIcon. Uses the default timeout of 30 seconds.
 /// </summary>
 /// <param name="iconStyle">The balloon ToolTip's icon to use. This icon is placed to the 
 /// left of the balloon ToolTip's title.</param>
 /// <param name="text">The text to display for the balloon ToolTip. The length of the text can not
 /// exceed 254 characters.</param>
 /// <param name="title">The text to display as a title for the balloon ToolTip. 
 /// This title appears in boldface above the text. It can have a maximum of 63 characters.
 /// Pass null or String.Empty to prevent the balloon from displaying a title.</param>
 /// <exception cref="ArgumentNullException">Text is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Text is longer than 254 characters.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Title is longer than 254 characters.</exception>
 public void ShowBalloon(BalloonIconStyle iconStyle, string text, string title)
 {
     ShowBalloon(iconStyle, text, title, 30000);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Displays a Balloon ToolTip for the current NotifyIcon. Uses the default timeout of 30 seconds.
 /// </summary>
 /// <param name="iconStyle">The balloon ToolTip's icon to use. This icon is placed to the
 /// left of the balloon ToolTip's title.</param>
 /// <param name="text">The text to display for the balloon ToolTip. The length of the text can not
 /// exceed 254 characters.</param>
 /// <param name="title">The text to display as a title for the balloon ToolTip.
 /// This title appears in boldface above the text. It can have a maximum of 63 characters.
 /// Pass null or String.Empty to prevent the balloon from displaying a title.</param>
 /// <exception cref="ArgumentNullException">Text is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Text is longer than 254 characters.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Title is longer than 254 characters.</exception>
 public void ShowBalloon(BalloonIconStyle iconStyle, string text, string title)
 {
     ShowBalloon(iconStyle, text, title, 30000);
 }