Previous | Index | Next 

KeyPreview property

This property isn’t available under VB.NET. The easiest way to simulate its behavior is to intercept the KeyDown, KeyUp, and KeyPress events of all the controls on the UserControl, using code like this:

        For Each ctrl As Control In Me.Controls
            AddHandler ctrl.KeyDown, AddressOf Control_KeyDown
            AddHandler ctrl.KeyUp, AddressOf Control_KeyUp
            AddHandler ctrl.KeyPress, AddressOf Control_KeyPress
        Next

VB Migration Partner fully supports the KeyPreview property; if the input focus is currently on a UserControl’s child control this property is True, any keyboard operation fires an event in the UserControl class first, and then in the child control that currently has the focus.

 

Previous | Index | Next