我正在使用{DELETE}助记符但在某些情况下我希望发生默认的删除操作。我以为我可以通过像SendKeys.Send(目标,键)之类的东西来做到这一点,但我找不到这样的选择。
具体来说,如果TextBox具有焦点,我希望进行默认处理(否则我需要自定义处理)。
这是我正在努力解决的代码:
private void _menuEditDelete_Click(object sender, EventArgs e)
{
if (_treeDocumentOutline.Focused)
{
DeleteNode();
}
else if (_gridAttributes.Focused)
{
DeleteSelectedRows();
}
else if (_gridAttributes.EditingControl != null && _gridAttributes.EditingControl.Focused)
{
// TODO: this is nuts...how to let the grid handle the key? Losing ability to undo/redo this way
var box = ((TextBox)_gridAttributes.EditingControl);
var selectionStart = box.SelectionStart;
var selectionEnd = box.SelectionStart + Math.Min(Math.Max(1, box.SelectionLength), box.Text.Length - box.SelectionStart);
box.Text = box.Text.Substring(0, selectionStart) + box.Text.Substring(selectionEnd);
box.SelectionStart = selectionStart;
box.SelectionLength = 0;
}
}