In Winforms, PreviewKeyDown() never fired for ANY key

前端 未结 3 1181
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 07:54

I was originally trying to get my program to get inputs of the arrow keys (Up, Down, Left and Right), but found out the hard way that in KeyDown(), those keys never made. Af

3条回答
  •  清酒与你
    2020-12-18 08:42

    I had the same problem!

    Luckily i found a dense answer :)

    you can use the bool function in the definition of the Form class witch occurs on every key pressed. but remember to return the base function!

    public partial class myForm : Form 
    {
        public myForm ()
        {
            InitializeComponent();
        }
    
        protected override bool ProcessDialogKey(Keys keyData)  
        {
            //Add your code here
    
            return base.ProcessDialogKey(keyData);  
        }
    }
    

    hopefully i helped. but if my answer is incomplete please note me!

提交回复
热议问题