Ejemplo n.º 1
0
        private void DisableCloseIfMultipleButtonsAndNoCancelButton()
        {
            if (_buttons.Count > 1)
            {
                if (_cancelButton != null)
                {
                    return;
                }

                //See if standard cancel button is present
                foreach (MessageBoxExButton button in _buttons)
                {
                    if (button.Text == MessageBoxExButtons.Cancel.ToString() && button.Value == MessageBoxExButtons.Cancel.ToString())
                    {
                        _cancelButton = button;
                        return;
                    }
                }

                //Standard cancel button is not present, Disable
                //close button
                DisableCloseButton(this);
                _allowCancel = false;
            }
            else if (_buttons.Count == 1)
            {
                _cancelButton = _buttons[0] as MessageBoxExButton;
            }
            else
            {
                //This condition should never get called
                _allowCancel = false;
            }
        }
Ejemplo n.º 2
0
        private void AddOkButtonIfNoButtonsPresent()
        {
            if (_buttons.Count == 0)
            {
                MessageBoxExButton okButton = new MessageBoxExButton();
                okButton.Text  = MessageBoxExButtons.Ok.ToString();
                okButton.Value = MessageBoxExButtons.Ok.ToString();

                _buttons.Add(okButton);
            }
        }
        /// <summary>
        /// Add a custom button to the message box
        /// </summary>
        /// <param name="button">The button to add</param>
        public void AddButton(MessageBoxExButton button)
        {
            if (button == null)
            {
                throw new ArgumentNullException("button", "A null button cannot be added");
            }

            _msgBox.Buttons.Add(button);

            if (button.IsCancelButton)
            {
                _msgBox.CustomCancelButton = button;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a button control based on info from MessageBoxExButton
        /// </summary>
        /// <param name="button"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private Button CreateButton(MessageBoxExButton button, Size size, Point location)
        {
            Button buttonCtrl = new Button();

            buttonCtrl.Size      = size;
            buttonCtrl.Text      = button.Text;
            buttonCtrl.TextAlign = ContentAlignment.MiddleCenter;
            buttonCtrl.FlatStyle = FlatStyle.System;
            if (button.HelpText != null && button.HelpText.Trim().Length != 0)
            {
                buttonToolTip.SetToolTip(buttonCtrl, button.HelpText);
            }
            buttonCtrl.Location = location;
            buttonCtrl.Click   += new EventHandler(OnButtonClicked);
            buttonCtrl.Tag      = button.Value;

            return(buttonCtrl);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the button control for the specified MessageBoxExButton, if the
        /// control has not been created this method creates the control
        /// </summary>
        /// <param name="button"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private Button GetButton(MessageBoxExButton button, Size size, Point location)
        {
            Button buttonCtrl = null;

            if (_buttonControlsTable.ContainsKey(button))
            {
                buttonCtrl          = _buttonControlsTable[button] as Button;
                buttonCtrl.Size     = size;
                buttonCtrl.Location = location;
            }
            else
            {
                buttonCtrl = CreateButton(button, size, location);
                _buttonControlsTable[button] = buttonCtrl;
                this.Controls.Add(buttonCtrl);
            }

            return(buttonCtrl);
        }
        /// <summary>
        /// Add a standard button to the message box
        /// </summary>
        /// <param name="buttons">The standard button to add</param>
        public void AddButton(MessageBoxExButtons button)
        {
            var btn = new MessageBoxExButton(button);

            AddButton(btn);
        }
        /// <summary>
        /// Add a custom button to the message box
        /// </summary>
        /// <param name="text">The text of the button</param>
        /// <param name="val">The return value in case this button is clicked</param>
        public void AddButton(string text, string val)
        {
            var button = new MessageBoxExButton(text, val);

            AddButton(button);
        }