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
        /// <summary>
        /// Layout all the controls
        /// </summary>
        private void LayoutControls()
        {
            panelIcon.Location  = new Point(LEFT_PADDING, TOP_PADDING);
            rtbMessage.Location = new Point(LEFT_PADDING + panelIcon.Width + ICON_MESSAGE_PADDING * (panelIcon.Width == 0 ? 0 : 1), TOP_PADDING);

            chbSaveResponse.Location = new Point(LEFT_PADDING + (int)(panelIcon.Width / 2),
                                                 TOP_PADDING + Math.Max(panelIcon.Height, rtbMessage.Height) + ITEM_PADDING);

            Size buttonSize      = GetButtonSize();
            int  allButtonsWidth = GetWidthOfAllButtons();

            int   firstButtonX       = ((int)(this.ClientSize.Width - allButtonsWidth) / 2);
            int   firstButtonY       = this.ClientSize.Height - BOTTOM_PADDING - buttonSize.Height;
            Point nextButtonLocation = new Point(firstButtonX, firstButtonY);

            for (int i = 0; i < _buttons.Count; i++)
            {
                MessageBoxExButton button     = (MessageBoxExButton)_buttons[i];
                Button             buttonCtrl = GetButton(button, buttonSize, nextButtonLocation);

                if ((i + 1) == _defaultButtonIndex)
                {
                    _defaultButtonControl = buttonCtrl;
                }

                nextButtonLocation.X += buttonSize.Width + BUTTON_PADDING;
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        /// <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.º 5
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.º 6
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);
        }
Ejemplo n.º 7
0
        /// <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)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text", "Text of a button cannot be null");
            }

            if (val == null)
            {
                throw new ArgumentNullException("val", "Value of a button cannot be null");
            }

            MessageBoxExButton button = new MessageBoxExButton();

            button.Text  = text;
            button.Value = val;

            AddButton(button);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add a standard button to the message box
        /// </summary>
        /// <param name="buttons">The standard button to add</param>
        public void AddButton(MessageBoxExButtons button)
        {
            string buttonText = MessageBoxExManager.GetLocalizedString(button.ToString());

            if (buttonText == null)
            {
                buttonText = button.ToString();
            }

            string buttonVal = button.ToString();

            MessageBoxExButton btn = new MessageBoxExButton();

            btn.Text         = buttonText;
            btn.Value        = buttonVal;
            btn.SystemButton = button;

            if (button == MessageBoxExButtons.Cancel)
            {
                btn.IsCancelButton = true;
            }

            AddButton(btn);
        }
Ejemplo n.º 9
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.º 10
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.º 11
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;
        }
Ejemplo n.º 12
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);
			}
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Add a standard button to the message box
		/// </summary>
		/// <param name="buttons">The standard button to add</param>
		public void AddButton(MessageBoxExButtons button)
		{
            string buttonText = MessageBoxExManager.GetLocalizedString(button.ToString());
            if(buttonText == null)
            {
                buttonText = button.ToString();
            }

            string buttonVal = button.ToString();

            MessageBoxExButton btn = new MessageBoxExButton();
            btn.Text = buttonText;
            btn.Value = buttonVal;
		    btn.SystemButton = button;

            if(button == MessageBoxExButtons.Cancel)
            {
                btn.IsCancelButton = true;
            }

			AddButton(btn);
		}
Ejemplo n.º 14
0
		/// <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)
		{
			if(text == null)
				throw new ArgumentNullException("text","Text of a button cannot be null");

			if(val == null)
				throw new ArgumentNullException("val","Value of a button cannot be null");

			MessageBoxExButton button = new MessageBoxExButton();
			button.Text = text;
			button.Value = val;

			AddButton(button);
		}
Ejemplo n.º 15
0
		/// <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;
			}
		}