Focus on toolstrip button vb.net

4.8k views Asked by At

I created a toolstrip with some buttons. I have a form with some objects (like textbox,checkbox,button etc.) and when i get the focus on last item,when i finish to compile i need with tab on keyboard to get focus on save button on the toolstrip.

Can anyone tell me how to do that? Because there isn't the focus option on toolstrip.

Thanks.

1

There are 1 answers

0
Hans Passant On

You'll need to override the Tab key handling. Say your last control is Button3 and the toolstrip button is SaveButton then the code looks like this:

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    If keyData = Keys.Tab AndAlso Me.ActiveControl Is Button3 Then
        ToolStrip1.Focus()
        SaveButton.Select()
        Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

Adjust as necessary to work with your specific controls.