Пример #1
0
 public static IntPtr ShowErrorToast(this Control parent,
                                     string text,
                                     int timeout             = 2500,
                                     eToastPosition position = eToastPosition.BottomCenter,
                                     int?x     = null,
                                     int?y     = null,
                                     Font font = null
                                     ) => parent.ShowToast(text, Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Abort, Color.Crimson, Color.White, null, Color.Crimson, font: font ?? _defaultFont, timeout: timeout);
Пример #2
0
 public static IntPtr ShowInfoToastMini(this Control parent,
                                        string text,
                                        int timeout             = 2500,
                                        eToastPosition position = eToastPosition.BottomCenter,
                                        int?x     = null,
                                        int?y     = null,
                                        Font font = null
                                        ) => parent.ShowToast(text, Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Info_32, Color.RoyalBlue, Color.White, null, Color.RoyalBlue, font: font ?? _defaultFont32, timeout: timeout);
Пример #3
0
 public static IntPtr ShowWarningToastMini(this Control parent,
                                           string text,
                                           int timeout             = 2500,
                                           eToastPosition position = eToastPosition.BottomCenter,
                                           int?x     = null,
                                           int?y     = null,
                                           Font font = null
                                           )
 {
     return(parent.ShowToast(text, Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Problem_32, Color.FromArgb(212, 57, 0), Color.White, null, Color.FromArgb(212, 57, 0), font: _defaultFont32, timeout: timeout));
 }
Пример #4
0
 public static IntPtr ShowSuccessToastMini(this Control parent,
                                           string text,
                                           int timeout             = 2500,
                                           eToastPosition position = eToastPosition.BottomCenter,
                                           int?x     = null,
                                           int?y     = null,
                                           Font font = null
                                           )
 {
     return(parent.ShowToast(text, Assets.FreeWp8Icons_White.FreeWp8IconsWhite_OK_32, Color.ForestGreen, Color.White, null, Color.ForestGreen, font: font ?? _defaultFont32, timeout: timeout));
 }
Пример #5
0
        public static IntPtr ShowToast(this Control parent,
                                       string text,
                                       Image image               = null,
                                       Color?backColor           = null,
                                       Color?foreColor           = null,
                                       eToastGlowColor?glowColor = null,
                                       Color?customGlowColor     = null,
                                       int timeout               = 2500,
                                       eToastPosition position   = eToastPosition.BottomCenter,
                                       int?x     = null,
                                       int?y     = null,
                                       Font font = null
                                       )
        {
            if (parent == null)
            {
                return(IntPtr.Zero);
            }
            //store parameter
            var bakForColor  = ToastNotification.ToastForeColor;
            var bakBackColor = ToastNotification.ToastBackColor;
            var bakFont      = ToastNotification.ToastFont;

            if (foreColor != null)
            {
                ToastNotification.ToastForeColor = foreColor.Value;
            }
            if (backColor.HasValue)
            {
                ToastNotification.ToastBackColor = backColor.Value;
            }
            ToastNotification.ToastFont = font ?? _defaultFont;
            if (customGlowColor != null)
            {
                ToastNotification.CustomGlowColor = customGlowColor.Value;
            }

            var ptr = x == null || y == null?
                      ToastNotification.Show(parent, text, image, timeout, glowColor ?? (customGlowColor == null ? ToastNotification.DefaultToastGlowColor : eToastGlowColor.Custom), position)
                          : ToastNotification.Show(parent, text, image, timeout, glowColor ?? (customGlowColor == null ? ToastNotification.DefaultToastGlowColor : eToastGlowColor.Custom), x.Value, y.Value);

            ToastNotification.ToastForeColor = bakForColor;
            ToastNotification.ToastBackColor = bakBackColor;
            ToastNotification.ToastFont      = bakFont;

            return(ptr);
        }
Пример #6
0
        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;
        }
Пример #7
0
 /// <summary>
 /// Displays the toast notification on top of the specified parent control, we recommend always using a parent form.
 /// </summary>
 /// <param name="parent">Parent form to display toast notification on top of</param>
 /// <param name="message">Message to display.</param>
 /// <param name="timeoutInterval">Interval in milliseconds after which the notification is hidden.</param>
 /// <param name="toastPosition">Specifies the position of the toast notification.</param>
 public static IntPtr Show(Control parent, string message, int timeoutInterval, eToastPosition toastPosition)
 {
     return Show(parent, message, null, timeoutInterval, _DefaultToastGlowColor, toastPosition);
 }
Пример #8
0
        private static Rectangle CalculateToastBounds(eToastPosition toastPosition, Rectangle parentClientRectangle, Size toastSize)
        {
            Rectangle displayBounds = Rectangle.Empty;
            if (toastPosition == eToastPosition.BottomCenter)
                displayBounds = new Rectangle(parentClientRectangle.X + (parentClientRectangle.Width - toastSize.Width) / 2,
                    parentClientRectangle.Bottom - toastSize.Height - _ToastMargin.Bottom,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.BottomLeft)
                displayBounds = new Rectangle(parentClientRectangle.X + _ToastMargin.Left,
                    parentClientRectangle.Bottom - toastSize.Height - _ToastMargin.Bottom,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.BottomRight)
                displayBounds = new Rectangle(parentClientRectangle.Right - _ToastMargin.Right - toastSize.Width,
                    parentClientRectangle.Bottom - toastSize.Height - _ToastMargin.Bottom,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.MiddleCenter)
                displayBounds = new Rectangle(parentClientRectangle.X + (parentClientRectangle.Width - toastSize.Width) / 2,
                    parentClientRectangle.Y + (parentClientRectangle.Height - toastSize.Height) / 2,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.MiddleLeft)
                displayBounds = new Rectangle(parentClientRectangle.X + _ToastMargin.Left,
                    parentClientRectangle.Y + (parentClientRectangle.Height - toastSize.Height) / 2,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.MiddleRight)
                displayBounds = new Rectangle(parentClientRectangle.Right - _ToastMargin.Right - toastSize.Width,
                    parentClientRectangle.Y + (parentClientRectangle.Height - toastSize.Height) / 2,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.TopCenter)
                displayBounds = new Rectangle(parentClientRectangle.X + (parentClientRectangle.Width - toastSize.Width) / 2,
                    parentClientRectangle.Y + _ToastMargin.Top,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.TopLeft)
                displayBounds = new Rectangle(parentClientRectangle.X + _ToastMargin.Left,
                    parentClientRectangle.Y + _ToastMargin.Top,
                    toastSize.Width, toastSize.Height);
            else if (toastPosition == eToastPosition.TopRight)
                displayBounds = new Rectangle(parentClientRectangle.Right - _ToastMargin.Right - toastSize.Width,
                    parentClientRectangle.Y + _ToastMargin.Top,
                    toastSize.Width, toastSize.Height);

            return displayBounds;
        }
Пример #9
0
 /// <summary>
 /// Displays the toast notification on top of the specified parent control, we recommend always using a parent form.
 /// </summary>
 /// <param name="parent">Parent form to display toast notification on top of</param>
 /// <param name="message">Message to display.</param>
 /// <param name="image">Image to display next to toast text.</param>
 /// <param name="timeoutInterval">Interval in milliseconds after which the notification is hidden.</param>
 /// <param name="toastGlowColor">Specifies toast-glow color used.</param>
 /// <param name="toastPosition">Specifies the position of the toast notification.</param>
 public static IntPtr Show(Control parent, string message, Image image, int timeoutInterval, eToastGlowColor toastGlowColor, eToastPosition toastPosition)
 {
     return ShowInternal(parent, message, image, timeoutInterval, toastGlowColor, toastPosition, 0, 0);
 }