API edit control losing focus on arrow keys
This thing keeps me in "what the..." category: whenever I push an arrow key in an edit control that I have created using API, the focus moves to any other control that is available. However, none of the tutorials, guides etc. have a mention about this feature. What causes this and how can I get the "normal" behavior for the arrow keys? Page up, down, home and end are working, but arrow keys not.
Also, I haven't seen a style flag that would affect this behavior.
Re: API edit control losing focus on arrow keys
I couldn't duplicate the problem.
Are you sure something isn't wrong in WndProc ? Have you tried in a fresh project ?
Can you post the code ?
Re: API edit control losing focus on arrow keys
For more details, I've wrapped the control in an usercontrol; and I can't make it much more "fresh" than it is.
VB Code:
' init styles
lngStyle = WS_CHILD Or WS_VISIBLE Or ES_NOHIDESEL
If m_MultiLine Then
Select Case m_ScrollBars
Case vbSBNone
lngStyle = lngStyle Or ES_MULTILINE Or ES_AUTOVSCROLL Or ES_AUTOHSCROLL
Case vbHorizontal
lngStyle = lngStyle Or ES_MULTILINE Or ES_AUTOHSCROLL Or WS_HSCROLL
Case vbVertical
lngStyle = lngStyle Or ES_MULTILINE Or ES_AUTOVSCROLL Or WS_VSCROLL
Case vbBoth
lngStyle = lngStyle Or ES_MULTILINE Or ES_AUTOHSCROLL Or WS_HSCROLL Or WS_VSCROLL
End Select
Else
lngStyle = lngStyle Or ES_AUTOHSCROLL
End If
' create new textbox
m_hWnd = CreateWindowExW(0&, StrPtr("Edit"), StrPtr(m_Text), _
lngStyle, _
m_BorderStyle, m_BorderStyle, m_RC.Right - m_BorderStyle * 2, m_RC.bottom - m_BorderStyle * 2, _
UserControl.hWnd, 0&, App.hInstance, 0&)
This is the part of the code that creates the edit control; before that only properties are read, then this code is next to be called. The only other extra I can think of is that the host usercontrol redirects the focus automatically to the edit control. Nothing else should have effect on the default behaviour of the control.