문제

I write small app for editing sql procedures and use great ScintillaNET code-editor control. I defined a Ctrl+S shortcut for saving files:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == (Keys.Control | Keys.S))
    {
            saveToolStripButton_Click(this.saveToolStripButton, null);
    }
    else if (keyData == (Keys.Control | Keys.O))
            openToolStripButton_Click(this.openToolStripButton, null);
    else if (keyData == (Keys.Control | Keys.N))
            newToolStripButton_Click(this.newToolStripButton, null);
    else if (keyData == (Keys.Control | Keys.W))
    {
            if (this.tabControl2.SelectedTab != null)
                    (this.tabControl2.SelectedTab as WorkspaceControl).closeSelectedFile();
    }

    return base.ProcessCmdKey(ref msg, keyData);
}

When I'm just resaving oldfile its all ok, but when its new file - after SaveFileDialog is closed and file saved - letter 's' is added to the end of my editor. How can I prevent it?

도움이 되었습니까?

해결책

The "s" is being added because base.ProcessCmdKey is being called even when it's not needed.

If you want to prevent further processing of the keystroke, just make sure you return true wherever appropriate.

다른 팁

You could use key_down event of scintilla control:

    private void scintilla_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.S && e.Control)
        {
            // Saving ...
            e.SuppressKeyPress = true;
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top