예제 #1
0
        /// <summary>
        /// Sends a pop-up dialog notification.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="buttons">The buttons.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        /// <param name="request">The operator request.</param>
        /// <param name="customButtonText">The custom button text if required.</param>
        /// <param name="customAction">The custom action if required.</param>
        /// <returns></returns>
        public static NotifyButton PopUp(string title, string message, NotifyButton buttons, LightStackColor blinkColor, string request = "", string customButtonText = "", Action customAction = null)
        {
            NotifyButton clickedButton = NotifyButton.Cancel;

            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, buttons, request, customButtonText, customAction))
                {
                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();
                        clickedButton = notify.ClickedButton;

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            return(clickedButton);
        }
예제 #2
0
        private static void notify_FormClosing(object sender, FormClosingEventArgs e)
        {
            NotifyForm notifyForm = sender as NotifyForm;

            if (notifyForm == null)
            {
                return;
            }

            if (notifyForm.ClickedCustomName == "Details")
            {
                notifyForm.Message += Environment.NewLine + Environment.NewLine + notifyForm.CustomButtonText;

                foreach (Button button in notifyForm.Buttons)
                {
                    if (button.Text == "Details")
                    {
                        button.Enabled = false;
                    }
                }

                e.Cancel = true;
            }
            else if (notifyForm.ClickedCustomName == "Copy")
            {
                string clipboardText = notifyForm.Title + Environment.NewLine + notifyForm.Message;

                if (!clipboardText.Contains(notifyForm.CustomButtonText))
                {
                    clipboardText += Environment.NewLine + Environment.NewLine + notifyForm.CustomButtonText;
                }

                Thread t = new Thread(obj => Clipboard.SetText(obj.ToString()));
                t.SetApartmentState(ApartmentState.STA);
                t.Start(clipboardText);

                e.Cancel = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Sends an error pop-up dialog notification. The border and title will be in red.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="details">The error details.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        public static void PopUpError(string title, string message, LightStackColor blinkColor, string details = "")
        {
            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            int notifyCount = 0;

            foreach (Form f in Application.OpenForms)
            {
                if (f is NotifyForm)
                {
                    notifyCount++;
                }
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, "", "Details", "Copy", "OK"))
                {
                    notify.BackColor        = Color.OrangeRed;
                    notify.CustomButtonText = details;
                    notify.FormClosing     += notify_FormClosing;

                    if (notifyCount > 0)
                    {
                        notify.StartPosition = FormStartPosition.Manual;
                        Rectangle bounds     = Screen.PrimaryScreen.Bounds;
                        Point center         = new Point((bounds.Width - notify.Width) / 2, (bounds.Height - notify.Height) / 2);
                        notify.Location      = new Point(center.X + (50 * notifyCount), center.Y + (50 * notifyCount));
                    }

                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });
        }
예제 #4
0
        /// <summary>
        /// Sends a pop-up dialog notification.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="request">The request.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        /// <param name="buttonNames">The custom button names.</param>
        /// <returns></returns>
        public static string PopUp(string title, string message, string request, LightStackColor blinkColor, params string[] buttonNames)
        {
            string customClickedName = "";

            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            int notifyCount = 0;

            foreach (Form f in Application.OpenForms)
            {
                if (f is NotifyForm)
                {
                    notifyCount++;
                }
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, request, buttonNames))
                {
                    if (notifyCount > 0)
                    {
                        notify.StartPosition = FormStartPosition.Manual;
                        Rectangle bounds     = Screen.PrimaryScreen.Bounds;
                        Point center         = new Point((bounds.Width - notify.Width) / 2, (bounds.Height - notify.Height) / 2);
                        notify.Location      = new Point(center.X + (50 * notifyCount), center.Y + (50 * notifyCount));
                    }

                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();
                        customClickedName = notify.ClickedCustomName;

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            return(customClickedName);
        }