public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "timeout", timeout.ToString(CultureInfo.CurrentCulture) })); } if (string.IsNullOrEmpty(tipText)) { throw new ArgumentException(System.Windows.Forms.SR.GetString("NotifyIconEmptyOrNullTipText")); } if (!System.Windows.Forms.ClientUtils.IsEnumValid(tipIcon, (int)tipIcon, 0, 3)) { throw new InvalidEnumArgumentException("tipIcon", (int)tipIcon, typeof(ToolTipIcon)); } if (this.added && !base.DesignMode) { System.Windows.Forms.IntSecurity.UnrestrictedWindows.Demand(); System.Windows.Forms.NativeMethods.NOTIFYICONDATA pnid = new System.Windows.Forms.NativeMethods.NOTIFYICONDATA(); if (this.window.Handle == IntPtr.Zero) { this.window.CreateHandle(new CreateParams()); } pnid.hWnd = this.window.Handle; pnid.uID = this.id; pnid.uFlags = 0x10; pnid.uTimeoutOrVersion = timeout; pnid.szInfoTitle = tipTitle; pnid.szInfo = tipText; switch (tipIcon) { case ToolTipIcon.None: pnid.dwInfoFlags = 0; break; case ToolTipIcon.Info: pnid.dwInfoFlags = 1; break; case ToolTipIcon.Warning: pnid.dwInfoFlags = 2; break; case ToolTipIcon.Error: pnid.dwInfoFlags = 3; break; } System.Windows.Forms.UnsafeNativeMethods.Shell_NotifyIcon(1, pnid); } }
private void UpdateIcon(bool showIconInTray) { lock (this.syncObj) { if (!base.DesignMode) { System.Windows.Forms.IntSecurity.UnrestrictedWindows.Demand(); this.window.LockReference(showIconInTray); System.Windows.Forms.NativeMethods.NOTIFYICONDATA pnid = new System.Windows.Forms.NativeMethods.NOTIFYICONDATA { uCallbackMessage = 0x800, uFlags = 1 }; if (showIconInTray && (this.window.Handle == IntPtr.Zero)) { this.window.CreateHandle(new CreateParams()); } pnid.hWnd = this.window.Handle; pnid.uID = this.id; pnid.hIcon = IntPtr.Zero; pnid.szTip = null; if (this.icon != null) { pnid.uFlags |= 2; pnid.hIcon = this.icon.Handle; } pnid.uFlags |= 4; pnid.szTip = this.text; if (showIconInTray && (this.icon != null)) { if (!this.added) { System.Windows.Forms.UnsafeNativeMethods.Shell_NotifyIcon(0, pnid); this.added = true; } else { System.Windows.Forms.UnsafeNativeMethods.Shell_NotifyIcon(1, pnid); } } else if (this.added) { System.Windows.Forms.UnsafeNativeMethods.Shell_NotifyIcon(2, pnid); this.added = false; } } } }
public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "timeout", timeout.ToString(CultureInfo.CurrentCulture) })); } if (string.IsNullOrEmpty(tipText)) { throw new ArgumentException(System.Windows.Forms.SR.GetString("NotifyIconEmptyOrNullTipText")); } if (!System.Windows.Forms.ClientUtils.IsEnumValid(tipIcon, (int) tipIcon, 0, 3)) { throw new InvalidEnumArgumentException("tipIcon", (int) tipIcon, typeof(ToolTipIcon)); } if (this.added && !base.DesignMode) { System.Windows.Forms.IntSecurity.UnrestrictedWindows.Demand(); System.Windows.Forms.NativeMethods.NOTIFYICONDATA pnid = new System.Windows.Forms.NativeMethods.NOTIFYICONDATA(); if (this.window.Handle == IntPtr.Zero) { this.window.CreateHandle(new CreateParams()); } pnid.hWnd = this.window.Handle; pnid.uID = this.id; pnid.uFlags = 0x10; pnid.uTimeoutOrVersion = timeout; pnid.szInfoTitle = tipTitle; pnid.szInfo = tipText; switch (tipIcon) { case ToolTipIcon.None: pnid.dwInfoFlags = 0; break; case ToolTipIcon.Info: pnid.dwInfoFlags = 1; break; case ToolTipIcon.Warning: pnid.dwInfoFlags = 2; break; case ToolTipIcon.Error: pnid.dwInfoFlags = 3; break; } System.Windows.Forms.UnsafeNativeMethods.Shell_NotifyIcon(1, pnid); } }