Exemplo n.º 1
0
        public override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);

            if (AllowKeyPress)
            {
                if (e.KeyChar == (char)Keys.Escape)
                {
                    switch (Buttons)
                    {
                    case MirMessageBoxButtons.OK:
                        if (OKButton != null && !OKButton.IsDisposed)
                        {
                            OKButton.InvokeMouseClick(null);
                        }
                        break;

                    case MirMessageBoxButtons.OKCancel:
                    case MirMessageBoxButtons.YesNoCancel:
                        if (CancelButton != null && !CancelButton.IsDisposed)
                        {
                            CancelButton.InvokeMouseClick(null);
                        }
                        break;

                    case MirMessageBoxButtons.YesNo:
                        if (NoButton != null && !NoButton.IsDisposed)
                        {
                            NoButton.InvokeMouseClick(null);
                        }
                        break;
                    }
                }

                else if (e.KeyChar == (char)Keys.Enter)
                {
                    switch (Buttons)
                    {
                    case MirMessageBoxButtons.OK:
                    case MirMessageBoxButtons.OKCancel:
                        if (OKButton != null && !OKButton.IsDisposed)
                        {
                            OKButton.InvokeMouseClick(null);
                        }
                        break;

                    case MirMessageBoxButtons.YesNoCancel:
                    case MirMessageBoxButtons.YesNo:
                        if (YesButton != null && !YesButton.IsDisposed)
                        {
                            YesButton.InvokeMouseClick(null);
                        }
                        break;
                    }
                }
                e.Handled = true;
            }
        }