protected override void OnKeyDown(KeyEventArgs e) { if (UIUtil.HandleCommonKeyEvent(e, true, this)) { return; } if (m_bSimpleTextOnly && IsPasteCommand(e)) { UIUtil.SetHandled(e, true); PasteAcceptable(); return; } if (m_bCtrlEnterAccepts && e.Control && ((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Enter))) { UIUtil.SetHandled(e, true); Debug.Assert(this.Multiline); Control p = this; Form f; while (true) { f = (p as Form); if (f != null) { break; } Control pParent = p.Parent; if ((pParent == null) || (pParent == p)) { break; } p = pParent; } if (f != null) { IButtonControl btn = f.AcceptButton; if (btn != null) { btn.PerformClick(); } else { Debug.Assert(false); } } else { Debug.Assert(false); } return; } base.OnKeyDown(e); }
protected override Boolean ProcessCmdKey(ref Message msg, Keys keyData) { if (AcceptButton is null || keyData != Keys.Enter) { return(base.ProcessCmdKey(ref msg, keyData)); } AcceptButton.PerformClick(); return(true); }
protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Enter) { IButtonControl control2 = Control.FromChildHandle(System.Design.UnsafeNativeMethods.GetFocus()) as IButtonControl; if ((control2 != null) && (control2 is Control)) { control2.PerformClick(); return(true); } } return(base.ProcessDialogKey(keyData)); }
/// <summary> /// Overridden to process Enter and Escape keys /// </summary> /// <param name="keyData"></param> /// <returns></returns> protected override bool ProcessDialogKey(Keys keyData) { if (base.ProcessDialogKey(keyData)) { return(true); } //if none of the other controls handled it using default processing, // then try our Accept and Cancel buttons, if they are assigned. if (keyData == Keys.Return && _acceptButton != null) { _acceptButton.PerformClick(); return(true); // handled } else if (keyData == Keys.Escape && _cancelButton != null) { _cancelButton.PerformClick(); return(true); // handled } return(false); }