Frage

starting by saying I'm a newbie on C#, I would like to know how to manage on a TextBox, events like the CTRL + A, or CTRL + S, or CTRL + some digit.

TextBox has the method KeyDown, and I think I should use this, but I don't understand how to understand when a user presses first CTRL, then presses one random digit (still with pressed CTRL).

Thank you in advance.

War es hilfreich?

Lösung 2

On the KeyDown Method (or KeyUp or any other one dealing with KeyEventArgs) you can write:

private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if (e.KeyCode == Keys.E && e.Modifiers == Keys.Control)
    {
      //Both CTRL + E were pressed
    }
}

Andere Tipps

Try this in KeyDown or KeyUp or anywhere

if (Control.ModifierKeys.HasFlag(Keys.Control))
{ 
    //user is holding control
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top