How to get Keypress event in Windows Panel control in C#

后端 未结 4 1335
挽巷
挽巷 2021-02-20 12:37

i want to get keypress event in windows panel control in c#, is any body help for me...

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 13:21

    "Panel" objects cannot receive the "KeyPress" event correctly.

    I've created Panel overload:

    public class PersoPanel : Panel
    

    and used the overridden method ProcessCmdKey:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    

    to intercept pressed keys:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        MessageBox.Show("You press " + keyData.ToString());
    
        // dO operations here...
    
        return base.ProcessCmdKey(ref msg, keyData);
    }
    

提交回复
热议问题