简体   繁体   中英

Prevent passing keydown event from control to parent form?

I have a C#/.Net form with several controls. On all the controls the keydown events should be passed to the parent form except one.

Is there any way to prevent a specific control from passing such events?

Here is the solution :

Public Class MyControl
    Inherits WhatEverControl 'For example TextBox

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
          return false 'This control wont allow keydown events pass to the parent form
    End Function
End Class

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