Example #1
0
        protected override bool ProcessDialogKey(Keys keyData)
        {
            //
            // Overrides the default handling of the Escape key. When a cancel
            // button is present, the Escape key is not published through
            // KeyPreview. Because of this, no alternative handling is possible.
            // This override catches the Escape key before it is processed by
            // the framework and cancels default handling when the CancelPreview
            // event signals it has handled the Escape key.
            //

            if ((keyData & (Keys.Alt | Keys.Control)) == Keys.None)
            {
                Keys keyCode = keyData & Keys.KeyCode;

                if (keyCode == Keys.Escape)
                {
                    var e = new CancelPreviewEventArgs();

                    OnCancelPreview(e);

                    if (e.Handled)
                    {
                        return(true);
                    }
                }
            }

            return(base.ProcessDialogKey(keyData));
        }
Example #2
0
        protected virtual void OnCancelPreview(CancelPreviewEventArgs e)
        {
            var ev = CancelPreview;

            if (ev != null)
            {
                ev(this, e);
            }
        }
Example #3
0
        protected override bool ProcessDialogKey(Keys keyData)
        {
            //
            // Overrides the default handling of the Escape key. When a cancel
            // button is present, the Escape key is not published through
            // KeyPreview. Because of this, no alternative handling is possible.
            // This override catches the Escape key before it is processed by
            // the framework and cancels default handling when the CancelPreview
            // event signals it has handled the Escape key.
            //

            if ((keyData & (Keys.Alt | Keys.Control)) == Keys.None)
            {
                Keys keyCode = keyData & Keys.KeyCode;

                if (keyCode == Keys.Escape)
                {
                    var e = new CancelPreviewEventArgs();

                    OnCancelPreview(e);

                    if (e.Handled)
                    {
                        return true;
                    }
                }
            }

            return base.ProcessDialogKey(keyData);
        }
Example #4
0
 protected virtual void OnCancelPreview(CancelPreviewEventArgs e)
 {
     var ev = CancelPreview;
     if (ev != null)
         ev(this, e);
 }