A form's key events will fire when you press a key. Place a control on that form and it won't happen any more because that control has focus. There are exceptions to this however as you will see if you place just a h or v scrollbar on the form. The key event will fire because the scrollbars can't receive focus as is demonstrated by the following code:
So I've made my own special scrollbar usercontrol and i can't figure out how to have it leave the key events alone. I'm pretty sure that the problem is that my usercontrol can receive focus at the moment. I found that the way of doing this is "SetStyle(Windows.Forms.ControlStyles.Selectable, False)". I put that in the new event of my usercontrol and now it looks like this:Code:Private Sub ScrollBar1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.GotFocus Debug.Print("Scroll GF") End Sub Private Sub ScrollBar1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.LostFocus Debug.Print("Scroll LF") End Sub
For some reason the get focus and lost focus events will still fire and (i'm not sure if this really is the problem) the key events will fire as well which is the thing i'm really after.Code:Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. SetStyle(Windows.Forms.ControlStyles.Selectable, False) End Sub




Reply With Quote