سؤال

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