0

我正在使用 {DELETE} 助记符,但在某些情况下,我希望执行默认删除操作。我以为我可以通过 SendKeys.Send(target, keys) 之类的方法来做到这一点,但我找不到这样的选择。

特别是如果 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;

        }
    }
4

0 回答 0