View Full Version : Help With TAB, <Enter> and Clicking on Controls
gungadout
07-10-2010, 06:52
Hi Folks,
A few pointers, please.
I have a screen with some labels, some text boxes and two buttons.
1. I click on the first text box and enter some data. I then press TAB. The %EN_KILLFOCUS response is triggered as expected. However, instead of focus moving to the next text box (sequentially numbered one higher than the first text box), it moves to the first button. Subsequent TAB presses oscillate focus between the two buttons. I would like to have the focus move between text boxes. How can I achieve that? (I would also like the same to happen when I press <Enter>.)
2. I am unsure how to make a text box change its appearance when it has focus. The two buttons change their outlines OK when they have focus.
3. Sometimes I need to click on a new (different) textbox, or a button, twice before the control clicked on gets focus and responds. At other times I get an immediate response, especially for the first two textboxes I happen to click on after a button gets focus. I guess I must be doing something wrong in my code. Have you any idea conceptually the sort of thing that might be?
Note: When the %EN_KILLFOCUS response is detected for a text box, I transmit the contents of the text box to the database via
TextString = Control_GetText(hDlgCurrentScreen, ControlNo)
.
.
SendResult = TCP_Send(TCPFreeFile, "@(DFE@" + FieldNo + AM + TextString + "@DFE)@" + $CR)
(where FieldNo is a text version of ControlNo), and a response from the database is picked up via
Buffer = ""
Do
InBuffer = TCP_Recv(TCPFreeFile, 1024*2)
Buffer += InBuffer
Loop While ((Len(InBuffer) > 0) And (Err = 0))
I then decode the text string from the data base, and if appropriate redisplay the data via
Control Set Text hDlgCurrentScreen, ControlNo, TextString
I have included this information in case it has some bearing on any of the matters above.
Thanks in advance,
Peter H. (gungadout)
Petr Schreiber
07-10-2010, 11:49
Hi Peter,
Ad 1
The tab order is determined not by IDs, but by the order you create your controls in the code. If you want to get to next textbox after first one, just create one after each other immediately in the code.
Ad 2
On Windows 7, textbox with focus has blue border.
If you want other solution, what about:
Store all textbox IDs in Array
In case any textbox recieves focus, change its background color (to yellow for example) and to other set white (others received from array)
Ad 3
This seems like two controls overlapping, hard to say, maybe you could post just the standalone dialog code?
Hope it helps,
Petr
gungadout
08-10-2010, 06:45
Hi Petr,
Thanks for your response.
1. I pre-allocate my control Ids for labels, text boxes and buttons. I then create only those which are necessary for the particular database program I am replicating. The labels, text boxes and buttons are created in order, one after the other, using the predefined control Ids.
' allow for up to 10 screen buttons
%btnScr01 = 1101
%btnScr02 = 1102
%btnScr03 = 1103
%btnScr04 = 1104
%btnScr05 = 1105
%btnScr06 = 1106
%btnScr07 = 1107
%btnScr08 = 1108
%btnScr09 = 1109
%btnScr10 = 1110
'allow for up to 30 screen labels
%lblScr01 = 1201
%lblScr02 = 1202
%lblScr03 = 1203
%lblScr04 = 1204
%lblScr05 = 1205
%lblScr06 = 1206
%lblScr07 = 1207
%lblScr08 = 1208
%lblScr09 = 1209
%lblScr10 = 1210
%lblScr11 = 1211
%lblScr12 = 1212
%lblScr13 = 1213
%lblScr14 = 1214
%lblScr15 = 1215
%lblScr16 = 1216
%lblScr17 = 1217
%lblScr18 = 1218
%lblScr19 = 1219
%lblScr20 = 1220
%lblScr21 = 1221
%lblScr22 = 1222
%lblScr23 = 1223
%lblScr24 = 1224
%lblScr25 = 1225
%lblScr26 = 1226
%lblScr27 = 1227
%lblScr28 = 1228
%lblScr29 = 1229
%lblScr30 = 1230
' allow for up to 30 screen text boxes
%txtScr01 = 1301
%txtScr02 = 1302
%txtScr03 = 1303
%txtScr04 = 1304
%txtScr05 = 1305
%txtScr06 = 1306
%txtScr07 = 1307
%txtScr08 = 1308
%txtScr09 = 1309
%txtScr10 = 1310
%txtScr11 = 1311
%txtScr12 = 1312
%txtScr13 = 1313
%txtScr14 = 1314
%txtScr15 = 1315
%txtScr16 = 1316
%txtScr17 = 1317
%txtScr18 = 1318
%txtScr19 = 1319
%txtScr20 = 1320
%txtScr21 = 1321
%txtScr22 = 1322
%txtScr23 = 1323
%txtScr24 = 1324
%txtScr25 = 1325
%txtScr26 = 1326
%txtScr27 = 1327
%txtScr28 = 1328
%txtScr29 = 1329
%txtScr30 = 1330
The text boxes and buttons are created as per the following code. There is a function for text boxes and a function for buttons. Labels are produced similarly. The database end sends instructions to the thinBasic front end to create all the labels first, then all the data fields, then all the buttons. The controls are created in a loop which calls the appropriate function each time.
Function ButtonCreate()
ControlNo = %btnScr01 + ButtonNo - 1 ' the database (server) end numbers the buttons 1 to 10
Control Add Button , hDlgCurrentScreen, ControlNo, TextString, HorizontalStart , VerticalStart, Width, Depth
.
.
Function DataFieldCreate()
ControlNo = %txtScr01 + FieldNo - 1 ' the database (server) end numbers the data (text) fields 1 to 30
Control Add Textbox , hDlgCurrentScreen, ControlNo, TextString, HorizontalStart , VerticalStart, Width, Depth, %BS_NOTIFY
.
.
Function DataFieldPopulate() ' used to change the contents of a text box
ControlNo = %txtScr01 + FieldNo - 1 ' the database (server) end numbers the data (text) fields 1 to 30
Control Set Text hDlgCurrentScreen, ControlNo, TextString
Is there something wrong with this method?
2. I am using Windows XP SP3. In the attachment, I have 2 screen dumps. In the first, the textbox next to the Period label has been clicked and had data entered into it, and therefore has focus. Yet, all the text fields seem to have the same kind of border. In the second screen, the Display button has been clicked, and clearly shows the blue border.
3. The attachments should show that no fields overlap. As noted before, repeated pressing of the Tab button oscillates the focus between the two buttons. The dialog code follows. Could it be, because I have predefined control Ids in discontinuous ranges with some of the defined ones remaining unused, that that is causing the problem? if so, I will have to scrap the predefined control Ids and keep arrays of those that are allocated, on the fly.
'-------------------------------------------------------------------------------------------------------
CallBack Function cbDialogScreen()
Select Case Callback_Message
Case %WM_COMMAND ' PEH this checks if it is an ordinary command, like a button press.
' -- Handling multiple buttons
ScreenFieldNumber = Callback_Control
ScreenFieldMessage = CBCTLMSG
If ScreenFieldNumber >= %btnScr01 And ScreenFieldNumber <= %btnScr10 Then ' was a button clicked?
ButtonNo = ScreenFieldNumber + 1 - %btnScr01
Select Case ButtonTextArray(ButtonNo)
Case "Exit"
Dialog End hDlgCurrentScreen
SendResult = TCP_Send(TCPFreeFile, "\EX" + $CR)
Case "File"
Case "Delete"
Case Else
SendResult = TCP_Send(TCPFreeFile, "@(BR@" + ButtonNo + "@BR)@" + $CR)
ProcessReply()
ProcessInputString()
End Select
End If
If ScreenFieldNumber >= %txtScr01 And ScreenFieldNumber <= %txtScr30 Then ' was a field accessed?
Select Case ScreenFieldMessage ' ScreenFieldMessage holds status feedback about the field
Case %EN_SETFOCUS 'control has just received focus
FieldNo = ScreenFieldNumber - %txtScr01 + 1
TextString = Control_GetText(hDlgCurrentScreen, ScreenFieldNumber)
SendResult = TCP_Send(TCPFreeFile, "@(DFS@" + FieldNo + AM + TextString + "@DFS)@" + $CR)
ProcessReply()
TestString = LEFT$(Buffer,5)
If TestString = "@(DP@" Then
DataFieldPopulate()
End If
TestString = LEFT$(Buffer,5)
If TestString = "@(MB@" Then
MessageBoxDisplay() ' if an error found at the database end
End If
TestString = LEFT$(Buffer,5)
Case %EN_KILLFOCUS 'control has just lost focus
FieldNo = ScreenFieldNumber - %txtScr01 + 1
TextString = Control_GetText(hDlgCurrentScreen, ScreenFieldNumber)
SendResult = TCP_Send(TCPFreeFile, "@(DFE@" + FieldNo + AM + TextString + "@DFE)@" + $CR)
ProcessReply()
TestString = LEFT$(Buffer,5)
If TestString = "@(DP@" Then
DataFieldPopulate()
End If
TestString = LEFT$(Buffer,5)
If TestString = "@(MB@" Then
MessageBoxDisplay() ' if an error found at the database end
End If
End Select
End If
Case %WM_CLOSE
' -- Add here some de-initialization if needed
Exit Function
End Select
End Function
Once again, thanks for your help.
Regards,
Peter H. (gungadout)
Petr Schreiber
08-10-2010, 12:13
Hi Peter,
well, I admit I am not sure what is going on in this case.
I may add one advice which could save bit of typing. To define continuous sets of IDs, you could do simply this:
Begin ControlID
' allow for up to 10 screen buttons
%btnScr01
%btnScr02
%btnScr03
%btnScr04
%btnScr05
%btnScr06
%btnScr07
%btnScr08
%btnScr09
%btnScr10
'allow for up to 30 screen labels
%lblScr01
%lblScr02
%lblScr03
%lblScr04
%lblScr05
%lblScr06
%lblScr07
%lblScr08
%lblScr09
%lblScr10
%lblScr11
%lblScr12
%lblScr13
%lblScr14
%lblScr15
%lblScr16
%lblScr17
%lblScr18
%lblScr19
%lblScr20
%lblScr21
%lblScr22
%lblScr23
%lblScr24
%lblScr25
%lblScr26
%lblScr27
%lblScr28
%lblScr29
%lblScr30
' allow for up to 30 screen text boxes
%txtScr01
%txtScr02
%txtScr03
%txtScr04
%txtScr05
%txtScr06
%txtScr07
%txtScr08
%txtScr09
%txtScr10
%txtScr11
%txtScr12
%txtScr13
%txtScr14
%txtScr15
%txtScr16
%txtScr17
%txtScr18
%txtScr19
%txtScr20
%txtScr21
%txtScr22
%txtScr23
%txtScr24
%txtScr25
%txtScr26
%txtScr27
%txtScr28
%txtScr29
%txtScr30
End ControlID
The ControlID block will take care of creating IDs with value growing by one.
The only major oddity I see in your code is that you set %BS_NOTIFY style to TextBox, but it is not valid equate for style. If you check the help topic for creation of textbox control, the equates start %ES_ or %WS_ but never %BS_. Let the textbox without style explicitly specified and let us know.
Petr
gungadout
08-10-2010, 15:36
Hi Petr,
Thanks for the tips.
I'll try them tomorrow. (Just got back home. Well after midnight here.)
Regards,
Peter H. (gungadout)