axel
axel

Reputation: 4127

c# - how to manage CONTROL + digit on a TextBox?

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.

Upvotes: 0

Views: 143

Answers (2)

user2480047
user2480047

Reputation:

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
    }
}

Upvotes: 0

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73452

Try this in KeyDown or KeyUp or anywhere

if (Control.ModifierKeys.HasFlag(Keys.Control))
{ 
    //user is holding control
}

Upvotes: 1

Related Questions