Ejemplo n.º 1
0
        internal static DialogResult Show(string messageText, string messageTitle, CustomMessageBoxIcon messageIcon)
        {
            CustomMessageBox frmMessage = new CustomMessageBox();

            frmMessage.setMessage(messageText);
            frmMessage.Text = messageTitle;
            frmMessage.addIconImage(messageIcon);
            frmMessage.addButton(CustomMessageBoxButtons.OK);
            return(frmMessage.ShowDialog());
        }
Ejemplo n.º 2
0
        public static DialogResult Show(string messageText, string messageTitle, CustomMessageBoxIcon messageIcon, int width = 442, int height = 135)
        {
            CustomMessageBox frmMessage = new CustomMessageBox();

            frmMessage.SetSize(width, height);
            frmMessage.setMessage(messageText);

            frmMessage.Text = messageTitle;
            frmMessage.addIconImage(messageIcon);
            frmMessage.addButton(CustomMessageBoxButtons.OK);

            return(frmMessage.ShowDialog());
        }
Ejemplo n.º 3
0
        private void AgregarImagen(CustomMessageBoxIcon customMessageBoxIcon)
        {
            switch (customMessageBoxIcon)
            {
            case CustomMessageBoxIcon.Info: pbIcon.Image = Resources.info; break;

            case CustomMessageBoxIcon.Error: pbIcon.Image = Resources.error; break;

            case CustomMessageBoxIcon.Warning: pbIcon.Image = Resources.warning; break;

            case CustomMessageBoxIcon.Success: pbIcon.Image = Resources.success; break;

            default: throw new InvalidOperationException($"No se encuentra implementado el tipo {customMessageBoxIcon.ToString()}");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// We can use this method to add image on message box.
        /// I had taken all images in ImageList control so that
        /// I can eaily add images. Image is displayed in
        /// PictureBox control.
        /// </summary>
        /// <param name="MessageIcon">Type of image to be displayed.</param>
        private void addIconImage(CustomMessageBoxIcon MessageIcon)
        {
            switch (MessageIcon)
            {
            case CustomMessageBoxIcon.Error:
                pictureBox1.Image = Bitmap.FromHicon(new Icon(SystemIcons.Error, 48, 48).Handle);      //Error is key name in imagelist control which uniqly identified images in ImageList control.
                break;

            case CustomMessageBoxIcon.Information:
                //pictureBox1.Image = imageList1.Images["Information"];
                pictureBox1.Image = Bitmap.FromHicon(new Icon(SystemIcons.Information, 48, 48).Handle);    //.Handle)  SystemIcons.Information;
                break;

            case CustomMessageBoxIcon.Question:
                pictureBox1.Image = Bitmap.FromHicon(new Icon(SystemIcons.Question, 48, 48).Handle);
                break;

            case CustomMessageBoxIcon.Warning:
                pictureBox1.Image = Bitmap.FromHicon(new Icon(SystemIcons.Warning, 48, 48).Handle);
                break;
            }
        }
Ejemplo n.º 5
0
        public static DialogResult ShowDialog(string texto, string titulo, MessageBoxButtons messageBoxButtons, CustomMessageBoxIcon customMessageBoxIcon, DialogResult defaultButton, Font fuente, int?timeOut)
        {
            CustomMessageBox messageBoxTest = InicializarMessageBox(texto, titulo, fuente);

            messageBoxTest.Botones = messageBoxTest.ObtenerBotones(messageBoxButtons, fuente, defaultButton);
            messageBoxTest.AgregarImagen(customMessageBoxIcon);
            messageBoxTest.AgregarBoton();
            messageBoxTest.PonerFocoEnDefaultButton();

            if (timeOut.HasValue)
            {
                messageBoxTest.InicializarTimeOut(timeOut.Value);
            }

            return(messageBoxTest.ShowDialog());
        }
Ejemplo n.º 6
0
 public static DialogResult ShowDialog(string texto, string titulo, MessageBoxButtons messageBoxButtons, CustomMessageBoxIcon customMessageBoxIcon)
 {
     return(ShowDialog(texto, titulo, messageBoxButtons, customMessageBoxIcon, DialogResult.None, DEFAULT_FONT, null));
 }
Ejemplo n.º 7
0
        public static CustomMessageBoxResult Show(string messageBoxText, CustomMessageBoxButton messageBoxButton, CustomMessageBoxIcon messageBoxImage)
        {
            CustomMessageBoxWindow window = new CustomMessageBoxWindow();

            //window.Owner = Application.Current.MainWindow;
            window.Topmost        = true;
            window.MessageBoxText = messageBoxText;
            switch (messageBoxImage)
            {
            case CustomMessageBoxIcon.Question:
                window.ImagePath       = @"/image/question.png";
                window.MessageBoxTitel = "提示";
                break;

            case CustomMessageBoxIcon.Error:
                window.ImagePath       = @"/image/error.png";
                window.MessageBoxTitel = "错误";
                break;

            case CustomMessageBoxIcon.Warning:
                window.ImagePath       = @"/image/alert.png";
                window.MessageBoxTitel = "警告";
                break;
            }
            switch (messageBoxButton)
            {
            case CustomMessageBoxButton.OK:
                window.OkButtonVisibility = Visibility.Visible;
                break;

            case CustomMessageBoxButton.OKCancel:
                window.OkButtonVisibility     = Visibility.Visible;
                window.CancelButtonVisibility = Visibility.Visible;
                break;

            case CustomMessageBoxButton.YesNo:
                window.YesButtonVisibility = Visibility.Visible;
                window.NoButtonVisibility  = Visibility.Visible;
                break;

            case CustomMessageBoxButton.YesNoCancel:
                window.YesButtonVisibility    = Visibility.Visible;
                window.NoButtonVisibility     = Visibility.Visible;
                window.CancelButtonVisibility = Visibility.Visible;
                break;

            default:
                window.OkButtonVisibility = Visibility.Visible;
                break;
            }

            window.ShowDialog();
            return(window.Result);
        }
Ejemplo n.º 8
0
        public static CustomMessageBoxResult Show(string title, string msg, CustomMessageBoxButton Buttons, CustomMessageBoxIcon BoxIcon)
        {
            Dialog dialog = new Dialog(Buttons);

            dialog.Title   = title;
            dialog.Message = msg;
            dialog.ShowDialog();
            return(dialog.Result);
        }
Ejemplo n.º 9
0
        public CustomMessageBox(
            string caption,
            CustomMessageBoxIcon icon       = CustomMessageBoxIcon.Default,
            CustomMessageBoxButtons buttons = CustomMessageBoxButtons.None,
            List <string> messageRows       = null,
            string prompt = null,
            CustomMessageBoxPromptValidation promptValidationMode = CustomMessageBoxPromptValidation.None,
            CustomMessageBoxFocus controlFocus = CustomMessageBoxFocus.Default)
        {
            DataContext = this;
            InitializeComponent();

            if (DesignerProperties.GetIsInDesignMode(this))
            {
            }
            else
            {
                // ToDo: Evil Hack to have the cake (see actual design in design mode) and eat it too (have different styles at runtime)
                this.Resources = null;
            }

            int currentIndex = 0;

            this.Title = caption;
            this.promptValidationMode = promptValidationMode;
            this.controlFocus         = controlFocus;

            var rowCaption = new RowDefinition();

            rowCaption.Height = GridLength.Auto;
            ContentGrid.RowDefinitions.Add(rowCaption);

            var captionTextBox = new System.Windows.Controls.TextBlock();

            var captionStyle = (Style)FindResource("VersionName_TextBox_Style");

            if (captionStyle != null)
            {
                captionTextBox.Style = captionStyle;
            }

            captionTextBox.Text = caption;
            ContentGrid.InsertAt(captionTextBox, 0, currentIndex);

            currentIndex++;

            switch (icon)
            {
            case CustomMessageBoxIcon.Information:
            {
                var informationStyle = (Style)FindResource("CustomMessageBoxInformationIconStyle");
                if (informationStyle != null)
                {
                    DialogImage.Style = informationStyle;
                }

                break;
            }

            case CustomMessageBoxIcon.Question:
            {
                var questionStyle = (Style)FindResource("CustomMessageBoxQuestionIconStyle");
                if (questionStyle != null)
                {
                    DialogImage.Style = questionStyle;
                }

                break;
            }

            case CustomMessageBoxIcon.Error:
            {
                var errorStyle = (Style)FindResource("CustomMessageBoxErrorIconStyle");
                if (errorStyle != null)
                {
                    DialogImage.Style = errorStyle;
                }

                break;
            }

            case CustomMessageBoxIcon.Default:
            {
                var defaultStyle = (Style)FindResource("CustomMessageBoxDefaultIconStyle");
                if (defaultStyle != null)
                {
                    DialogImage.Style = defaultStyle;
                }

                break;
            }
            }

            var textblockStyle = (Style)FindResource("CustomMessageBox_TextBlock_Style");

            if (messageRows != null && messageRows.Any())
            {
                foreach (var messgeRow in messageRows)
                {
                    var rowDefinition = new RowDefinition();
                    rowDefinition.Height = GridLength.Auto;
                    ContentGrid.RowDefinitions.Add(rowDefinition);

                    var tempTextBox = new System.Windows.Controls.TextBlock();
                    if (textblockStyle != null)
                    {
                        tempTextBox.Style = textblockStyle;
                    }

                    tempTextBox.Text = messgeRow;
                    ContentGrid.InsertAt(tempTextBox, 0, currentIndex);

                    currentIndex++;
                }
            }

            if (prompt != null)
            {
                var promptRow = new RowDefinition();
                promptRow.Height = GridLength.Auto;
                ContentGrid.RowDefinitions.Add(promptRow);

                promptTextBox = new System.Windows.Controls.TextBox();
                var promptStyle = (Style)FindResource("MainWindowTextBoxStyle");
                if (promptStyle != null)
                {
                    promptTextBox.Style = promptStyle;
                }

                promptTextBox.Name         = "DialogPromptTextBox";
                promptTextBox.IsEnabled    = true;
                promptTextBox.IsReadOnly   = false;
                promptTextBox.TextChanged += PromptTextBox_TextChanged;
                promptTextBox.Text         = prompt;
                ContentGrid.InsertAt(promptTextBox, 0, currentIndex);

                if (controlFocus == CustomMessageBoxFocus.Prompt)
                {
                    promptTextBox.Focus();
                    promptTextBox.Select(0, prompt.Length);
                }

                currentIndex++;
            }

            if (buttons != CustomMessageBoxButtons.None)
            {
                var tempButton  = new SvgImageButton1();
                var buttonStyle = (Style)FindResource("SvgAcceptButton");
                if (buttonStyle != null)
                {
                    tempButton.Style = buttonStyle;
                }

                tempButton.HorizontalAlignment = HorizontalAlignment.Right;
                tempButton.Click    += OkButton_Click;
                tempButton.IsDefault = true;
                DialogGrid.InsertAt(tempButton, 1, 3);

                if (controlFocus == CustomMessageBoxFocus.Ok)
                {
                    tempButton.Focus();
                }

                if (buttons == CustomMessageBoxButtons.OkAndCancel)
                {
                    var cancelButton      = new SvgImageButton1();
                    var cancelButtonStyle = (Style)FindResource("SvgCancelButton");
                    if (cancelButtonStyle != null)
                    {
                        cancelButton.Style = cancelButtonStyle;
                    }

                    cancelButton.HorizontalAlignment = HorizontalAlignment.Left;
                    cancelButton.Click += CancelButton_Click;
                    DialogGrid.InsertAt(cancelButton, 0, 3);

                    if (controlFocus == CustomMessageBoxFocus.Cancel)
                    {
                        cancelButton.Focus();
                    }
                }

                currentIndex++;
            }
        }