Hi All
I am adding to an old program.
It has a tabcontrol with multiple pages.
I have always used the FF_control_setfocus to the First Textbox on every child-form during the Function FORM1_TABCONTROL1_TCN_SELCHANGE event. That way once you click a tab, it sets the focus to the relevant textbox.
Now I had to add another Tabcontrol on one of the Child Forms.
The same command now doesn't work. For instance, if i click Tab1 on form 1 it opens the relevant tab with the right child form(the one with another tab control on it), but cannot set the set-focus tp a text-box on it . It simply ignores the command.
If i move the command to that Tab-control's celchange event it work, but not from the first tab-control.
(If this now makes any sense :) )
Surely one could set the focus to a textbox on a child form on a different tab-control?
When I hear questions like this I tend to think that it may be a timing issue where the focus is set but then an action with the sub tab control is stealing that focus elsewhere. A simple solution would be to create a user defined message (say, MSG_USER_SETFOCUS) and then use POSTMESSAGE in your SelChange event to post that message to the Form. When you send it you could even specify the handle of the control that you want to set focus to as the WPARAM of the message. Maybe something like:
PostMessage HWND_FRMMAIN, MSG_USER_SETFOCUS, HWND_FRMMAIN_TEXT1, 0
The in the CUSTOM handler of the form you would catch and handle the MSG_USER_SETFOCUS message.
Select Case wMsg
Case MSG_USER_SETFOCUS
SetFocus wParam
Thanks for the reply Paul.
This is what I have done so far:
On the main form's tabcontrol selchange I did this:
Function FORM1_TABCONTROL1_TCN_SELCHANGE ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
ByVal lpNMHDR As NMHDR Ptr _ ' pointer to NMHDR
) As Long
mytab& = FF_TabControl_GetSelectedTab(HWND_FORM1_TABCONTROL1)
If mytab& = 0 Then FF_Control_SetFocus(hwnd_form2_text1)
If mytab& = 1 Then FF_Control_SetFocus(hwnd_form3_text1)
If mytab& = 2 Then FF_Control_SetFocus(hwnd_form4_text1)
If mytab& = 3 Then FF_Control_SetFocus(hwnd_form5_text1)
If mytab& = 4 Then FF_Control_SetFocus(hwnd_form6_text1)
If mytab& = 5 Then
FF_Control_SetFocus(hwnd_form7_xpbutton2)
Loadinfo
End If
If mytab& = 6 Then '--International menu
FF_TabControl_SetTabFocus( HWND_INTERNAT_TABCONTROL1,0)
PostMessage HWND_Receive, MSG_USER_SETFOCUS, HWND_RECEIVE_TEXT1, 0 'The form name is "receive"
End If
Function = 0 ' change according to your needs
End Function
Then in the receiving Form's custom i did this:
Function RECEIVE_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case MSG_USER_SETFOCUS
SetFocus wParam
Function = 0 ' change according to your needs
End Select
End Function
Do i need to declare something first? I am getting a compiler error #516. Probably just a TYPO I made.
In PowerBASIC, constants use a % prefix, so the constant must be %MSG_USER_SETFOCUS, and, of course, you have to define that constant, i.e. %MSG_USER_SETFOCUS = some value.
Thanks Josè.
I will go do that immediately.
So obvious to declare that first!!
Now the Postmessage runs correctly, but the focus still isn't set.
Will dig a bit and see what i can come up with.
Thanks a million.
O, I can be the biggest Idiot some times.
Overlook the simple obvious. Right there, smack bang, right in front of me...
Thanks guys, remind me next time just to read my code a few times! :)