private static IntPtr ShowInternal(Control parent, string message, Image image, int timeoutInterval, eToastGlowColor toastGlowColor, eToastPosition? toastPosition, int x, int y) { if (parent == null) throw new NullReferenceException("parent parameter for toast notification must be set."); if (timeoutInterval < 1) timeoutInterval = 0; ToastDisplay toast = new ToastDisplay(); toast.BackColor = Color.Transparent; toast.ToastBackColor = _ToastBackColor; toast.ForeColor = _ToastForeColor; if (_ToastFont != null) toast.Font = _ToastFont; bool isTerminalSession = NativeFunctions.IsTerminalSession(); toast.Alpha = isTerminalSession ? 255 : 0; toast.Text = message; toast.Image = image; toast.GlowColor = toastGlowColor; parent.Controls.Add(toast); Size toastSize = toast.DesiredSize(_ToastMargin, parent.ClientRectangle); toast.BringToFront(); if (toastPosition != null) toast.Bounds = CalculateToastBounds(toastPosition.Value, parent.ClientRectangle, toastSize); else toast.Bounds = new Rectangle(x, y, toastSize.Width, toastSize.Height); toast.Visible = true; IntPtr toastId = toast.Handle; if (!isTerminalSession) { Animation.AnimationInt anim = new DevComponents.DotNetBar.Animation.AnimationInt(new Animation.AnimationRequest(toast, "Alpha", 0, 255), Animation.AnimationEasing.EaseOutQuad, 250); //anim.FixedStepCount = 10; anim.AutoDispose = true; anim.Start(); } if (timeoutInterval > 0) BarUtilities.InvokeDelayed(new MethodInvoker(delegate { CloseToast(toast); }), timeoutInterval); return toastId; }
private static void CloseToast(ToastDisplay toast) { bool isTerminalSession = NativeFunctions.IsTerminalSession(); if (toast.IsDisposed) { if (toast.Parent != null) toast.Parent.Controls.Remove(toast); return; } if (isTerminalSession) { toast.Visible = false; toast.Parent.Controls.Remove(toast); toast.Dispose(); } else { Animation.AnimationInt anim = new DevComponents.DotNetBar.Animation.AnimationInt(new Animation.AnimationRequest(toast, "Alpha", 255, 0), Animation.AnimationEasing.EaseInQuad, 250); anim.AutoDispose = true; anim.Start(); anim.AnimationCompleted += new EventHandler(delegate { if (toast.Parent != null) toast.Parent.Controls.Remove(toast); toast.Dispose(); }); } }