简体   繁体   中英

keydown to correspond with button down

Hello I am trying to match the button down visual (on the WinForm, the button boarder gets a little darker, indicating it is pressed) with a keydown event. First of all I need to detect a keydown for numbers only. Then when the key goes down, the corresponding number button on the form should look like it is depressed as well. Sorry if this is already been answered using differt jargon. I already know how to perform a button click with the keydown.

Make a test code on KeyDown event. Write down the keyboard codes you shall see from pressing 0 to 9. Then use those keyboard codes in your KeyDown's if statement

You can use a Checkbox and set the appearance to be Button . Then you can do something like this:

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        //if key
        checkBox1.Checked = true;
    }

    private void OnKeyUp(object sender, KeyEventArgs e)
    {
        //if key
        checkBox1.Checked = false;
    }

As far as the Keys, you can just use the KeyEventArgs.KeyCode

e.KeyCode == Keys.D0 || .. || e.KeyCode == Keys.D9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM