コード例 #1
0
        /// <summary>
        /// Create a non blocking message box.
        /// </summary>
        /// <param name="configuration">The configuration for the message box.</param>
        public static void MessageBoxNonBlocking(DialogConfiguration configuration)
        {
            if (_parentForm == null)
            {
                return;
            }

            if (_parentForm.InvokeRequired)
            {
                _parentForm.Invoke(new MessageBoxNonBlockingCallback(MessageBoxNonBlocking), configuration);
            }
            else
            {
                new CustomDialogBox(_parentForm, configuration).Show();
                configuration.ResultUserInput = null;
            }
        }
コード例 #2
0
        /// <summary>
        /// Create a persistent message box. This is used when the application needs to update information on the dialog over time.
        /// will replace any existing persistent message box.
        /// </summary>
        /// <param name="configuration">The configuration of the message box.</param>
        public static void MessageBoxPersistentCreate(DialogConfiguration configuration)
        {
            if (_parentForm == null)
            {
                return;
            }

            if (_parentForm.InvokeRequired)
            {
                _parentForm.Invoke(new MessageBoxPersistentCreateCallback(MessageBoxPersistentCreate), configuration);
            }
            else
            {
                MessageBoxPersistentClose();
                _persistentDialog = new CustomDialogBox(_parentForm, configuration);
                _persistentDialog.Show();
            }
        }
コード例 #3
0
        /// <summary>
        /// Create a blocking message box. Will wait for user input to continue execution.
        /// </summary>
        /// <param name="configuration">The configuration for the message box.</param>
        /// <returns>User results.</returns>
        public static DialogResult MessageBoxBlocking(DialogConfiguration configuration)
        {
            if (_parentForm == null)
            {
                return(DialogResult.Cancel);
            }

            if (_parentForm.InvokeRequired)
            {
                return((DialogResult)_parentForm.Invoke(new MessageBoxBlockingCallback(MessageBoxBlocking), configuration));
            }

            var dialog = new CustomDialogBox(_parentForm, configuration);

            configuration.Result          = dialog.ShowDialog();
            configuration.ResultUserInput = dialog.ResultText;
            return(configuration.Result);
        }
コード例 #4
0
        /// <summary>
        /// Create a custom dialog.
        /// </summary>
        /// <param name="ownerForm"></param>
        /// <param name="configuration"></param>
        public CustomDialogBox(Form ownerForm, DialogConfiguration configuration)
        {
            InitializeComponent();
            imagePanel.Visible = false;

            MessageAlignment = configuration.MessageAlignment;

            Owner = ownerForm;

            Text         = configuration.Title;
            Message.Text = configuration.Message;
            Width        = configuration.DialogWidth;

            if (configuration.UserEntryFieldIsVisible)
            {
                textField.Focus();
                textField.UseSystemPasswordChar = configuration.UserEntryFieldIsPassword;
            }
            else
            {
                ok.Select();
                textField.Visible = false;
                textField.Enabled = false;
            }

            if (configuration.ButtonIsVisible)
            {
                switch (configuration.ButtonOptions)
                {
                case MessageBoxButtons.YesNo:
                    ok.Text       = "Yes";
                    cancel.Text   = "No";
                    _okResult     = DialogResult.Yes;
                    _cancelResult = DialogResult.No;
                    break;

                case MessageBoxButtons.OK:
                    ok.Text        = "OK";
                    cancel.Visible = false;
                    mainLayoutPanel.SetCellPosition(ok, new TableLayoutPanelCellPosition(0, 4));
                    mainLayoutPanel.SetColumnSpan(ok, 2);
                    _okResult     = DialogResult.OK;
                    _cancelResult = DialogResult.Cancel;
                    break;

                case MessageBoxButtons.OKCancel:
                    _okResult     = DialogResult.OK;
                    _cancelResult = DialogResult.Cancel;
                    break;

                case MessageBoxButtons.RetryCancel:
                    ok.Text       = "Retry";
                    _okResult     = DialogResult.Retry;
                    _cancelResult = DialogResult.Cancel;
                    break;

                default:
                    break;
                }
            }
            else
            {
                mainLayoutPanel.RowStyles[4].SizeType = SizeType.Absolute;
                mainLayoutPanel.RowStyles[4].Height   = 0;
            }

            foreach (Control c in mainLayoutPanel.Controls)
            {
                c.Font = new Font(Owner.Font.FontFamily, Owner.Font.Size,
                                  c.Name == "blankError" ? FontStyle.Bold : FontStyle.Regular);
            }

            if (!configuration.UserEntryFieldIsPassword)
            {
                var height = textField.Height;
                textField.Multiline = true;
                textField.Height    = height * (configuration.UserEntryFieldIsMultiline ? 6 : 1);
            }

            ResizeBox();

            if (configuration.DialogImage != null)
            {
                imagePanel.Visible = true;
                var ratio = configuration.DialogImage.Width / (double)configuration.DialogImage.Height;
                imagePanel.Width           = Math.Min((int)(imagePanel.Height * ratio), 400);
                imagePanel.BackgroundImage = configuration.DialogImage;
                Width  += imagePanel.Width + 6;
                Height += mainLayoutPanel.Height + 6;
            }

            ResizeBox();
        }