The custom control does not have a parent set at the time of instantiation. You probalby want to handle the control's ParentChanged event and add the handler in there:
Private Sub UserControl1_ParentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ParentChanged
If Not Me.Parent Is Nothing Then
AddHandler ParentForm.KeyDown, AddressOf KeyDownOnForm
End If
End Sub
You'll have to ensure that a parent exists before adding the handler.
GL!
|