|
Post by wexhammer on Jan 3, 2020 12:14:55 GMT -5
Hi everyone, i know its possible to set a default button with Stylebits so that when i press the return key on my keyboard i can get some results. However if when disabling the first default button, can another take default if i choose to? For example: one tab has a search bar with a default button which when clicked searches through some results, tab 2 has a search bar with another button which also would be nice to use as default one the other default is disabled and hidden, is this possible? Because so far iv'e had no luck!
Stylebits #main.expdefault, _BS_DEFPUSHBUTTON, 0, 0, 0
|
|
|
Post by sarossell on Jan 3, 2020 12:29:50 GMT -5
I have yet to write any useful GUI apps, but the help file suggests using the .default parameter:
button #win.default, "Okay",[okay],UL,200,100
I'm guessing that if it is used twice, and the other is hidden or disabled, it might behave as you describe.
Also, there is the setfocus command:
print #handle.button, "!setfocus"
|
|
|
Post by wexhammer on Jan 3, 2020 13:01:01 GMT -5
Thanks, i cannot get it to work within this program. Only one default works which is very strange. The buttons are supposed to be hidden and when value is typed in the textbox pressing enter should reveal the contents in a notice.
[InitColors] 'Please use default colors when possible. 'ForegroundColor$ = "Black" 'BackgroundColor$ = "Buttonface"
True = 1 : False = 0
[WindowSetup] NOMAINWIN WindowWidth = 485 : WindowHeight = 416 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup] Stylebits #main.default1, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default1, "Default 1", [default1], UL, 135, 20, 145, 40
Stylebits #main.default2, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default2, "Default 2", [default2], UL, 135, 215, 145, 40 checkbox #main.yesno, "Make default 2 a default instead", [enabledefault2], [enabledefault2_reset], 50, 110, 400, 25
textbox #main.default1entry, 135, 60, 145, 40
textbox #main.default2entry, 135, 265, 145, 40
Open "Default Buttons" for Window as #main #main "trapclose [quit]" #main "font ms_sans_serif 10" #main.default1 "!setfocus"
#main.default2 "!disable" #main.default2 "!hide" #main.default2entry "!hide"
#main.default1 "!hide" #main.default2 "!hide" [loop] Wait
[quit] close #main : END
[default1] #main.default1entry "!contents? default1$" notice default1$ wait
[default2] #main.default2entry "!contents? default2$" notice default2$ wait
[enabledefault2] #main.default1 "!setfocus" #main.yesno "value? result$" #main.default2 "!enable"
#main.default1 "!disable" #main.default1 "!hide" #main.default2entry "!show" #main.default1entry "!hide" wait
[enabledefault2_reset] #main.default2 "!setfocus" #main.default2entry "!hide" #main.yesno "value? result$" #main.default2 "!disable" #main.default2 "!hide" #main.default1 "!enable"
#main.default1entry "!show" wait
|
|
|
Post by tsh73 on Jan 3, 2020 14:29:26 GMT -5
(IMHO) stylebits are set BEFORE opening windows. So no way to change it from button to button. BUT all default button do is to call event handler on ENTER You want to change event handler, do you? So just put some logic (if then or select case) in that one default button event handler! (btw it doesn't event have to be visible - you can place it off-screen and it still work on ENTER as default button.)
EDIT oh, "!hide" works nice too
|
|
|
Post by tsh73 on Jan 3, 2020 14:43:57 GMT -5
[InitColors] 'Please use default colors when possible. 'ForegroundColor$ = "Black" 'BackgroundColor$ = "Buttonface"
True = 1 : False = 0
[WindowSetup] NOMAINWIN WindowWidth = 485 : WindowHeight = 416 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup] Stylebits #main.default1, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default1, "Default 1", [default1], UL, 135, 20, 145, 40
checkbox #main.yesno, "Make default 2 a default instead", [enabledefault2], [enabledefault2_reset], 50, 110, 400, 25
textbox #main.default1entry, 135, 60, 145, 40
textbox #main.default2entry, 135, 265, 145, 40
Open "Default Buttons" for Window as #main #main "trapclose [quit]" #main "font ms_sans_serif 10" #main.default1 "!setfocus" #main.default2entry "!hide" #main.default1 "!hide"
use1=1 [loop] Wait
[quit] close #main : END
[default1] if use1 then #main.default1entry "!contents? default1$" notice "default1"+chr$(13)+default1$ else #main.default2entry "!contents? default2$" notice "default2"+chr$(13)+default2$ end if wait
[default2] #main.default2entry "!contents? default2$" notice default2$ wait
[enabledefault2] #main.default1 "!setfocus" #main.yesno "value? result$" #main.default2entry "!show" #main.default1entry "!hide" use1=0 wait
[enabledefault2_reset] #main.default2entry "!hide" #main.yesno "value? result$" #main.default1entry "!show" use1=1 wait
|
|
|
Post by wexhammer on Jan 3, 2020 15:32:36 GMT -5
Brilliant, thank you for the help! It definitely makes more sense to put it in an "if then select case" than having a load of extra code lying about.
|
|
|
Post by wexhammer on Jan 3, 2020 16:13:49 GMT -5
Now i can use as many fields as i like with the default button!
Example:
True = 1 : False = 0
[WindowSetup] NOMAINWIN WindowWidth = 485 : WindowHeight = 416 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup] Stylebits #main.default1, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default1, "Default 1", [default1], UL, 135, 20, 145, 40
button #main.yes, "Def1", [switch1], UL, 40, 50, 130, 35 button #main.no, "Def2", [switch2], UL,40, 90, 130, 35 button #main.mid, "Def3", [switch3], UL,40, 130, 130, 35
TextboxColor$ = "red" textbox #main.default1entry, 175, 50, 145, 40
TextboxColor$ = "red" textbox #main.default2entry, 175, 90, 145, 40 TextboxColor$ = "red" textbox #main.default3entry, 175, 130, 145, 40
Open "Default Buttons" for Window as #main #main "trapclose [quit]" #main "font ms_sans_serif 10" #main.default1 "!setfocus"
#main.default1 "!hide"
#main.default1entry "!enable" #main.default2entry "!disable" #main.default3entry "!disable"
use1=1 [loop] Wait
[quit] close #main : END
[default1] if use1 = 1 then #main.default1entry "!contents? default1$" notice "default1"+chr$(13)+default1$ else if use1 = 0 then #main.default2entry "!contents? default2$" notice "default2"+chr$(13)+default2$ else if use1 = 2 then #main.default3entry "!contents? default3$" notice "default3"+chr$(13)+default3$ end if end if end if wait
[switch1] #main.default1entry "!enable" #main.default2entry "!disable" #main.default3entry "!disable"
#main.default1 "!setfocus"
use1=1 wait
[switch2] #main.default1entry "!disable" #main.default2entry "!enable" #main.default3entry "!disable"
#main.default1 "!setfocus"
use1=0 wait
[switch3]
#main.default1entry "!disable" #main.default2entry "!disable" #main.default3entry "!enable" #main.default1 "!setfocus"
use1=2 wait
|
|
|
Post by Rod on Jan 4, 2020 4:21:52 GMT -5
There can only be one "default" button that reacts to "enter". You must program this at the head of the program. As Anatoly has said it need not be in view. There will be one handler for this default button. That handler can handle as many textboxes as you like. Keeping track of where you are and what you are doing would allow you to toggle between tasks and hide or disable sets of buttons.
But you are in danger of confusing yourself as well as the user. Why not try and build the program so that one windows closes and another opens. That way you can set a new default button. But I think you focus too much on the need to react to "enter". Folks usually know there will be a button to press to move on, or move back, or redo what they were doing. "enter" can't accommodate all of that.
|
|
|
Post by wexhammer on Jan 4, 2020 11:17:09 GMT -5
Okay cool, i think the biggest thing of all in this case is the ease of access when moving between textfields, especially when entering data as its more time effective. Take for example i have 3 textfields to fill in, and after typing in the first hit enter and the second gains focus and so on...
I have some code here were i have tried to replicate just that, the code runs, however it doesnt seem to be giving what is intended above. What could be going wrong here?
True = 1 : False = 0
[WindowSetup] NOMAINWIN WindowWidth = 485 : WindowHeight = 416 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup] Stylebits #main.default1, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default1, "Default 1", [default1], UL, 135, 20, 145, 40
'button #main.yes, "Def1", [switch1], UL, 40, 50, 130, 35 'button #main.no, "Def2", [switch2], UL,40, 90, 130, 35 'button #main.mid, "Def3", [switch3], UL,40, 130, 130, 35
TextboxColor$ = "red" textbox #main.default1entry, 175, 50, 145, 40
TextboxColor$ = "red" textbox #main.default2entry, 175, 90, 145, 40 TextboxColor$ = "red" textbox #main.default3entry, 175, 130, 145, 40
Open "Default Buttons" for Window as #main #main "trapclose [quit]" #main "font ms_sans_serif 10" #main.default1 "!setfocus"
#main.default1 "!hide"
#main.default1entry "!enable" #main.default2entry "!disable" #main.default3entry "!disable"
use1=0 [loop] Wait
[quit] close #main : END
[default1] use1=use1+1
if use1 = 0 then #main.default1entry "!setfocus" ' notice "default1"+chr$(13)+default1$ else if use1 = 1 then #main.default2entry "!setfocus" 'notice "default2"+chr$(13)+default2$ else if use1 = 2 then #main.default3entry "!setfocus" 'notice "default3"+chr$(13)+default3$ end if end if end if wait
|
|
|
Post by Rod on Jan 4, 2020 14:39:52 GMT -5
I think you need to read about tab order. It is normal to move from one textbox to another in a formal pattern. This is standard paractice that everyone expects from a GUI.
|
|
|
Post by wexhammer on Jan 4, 2020 15:16:40 GMT -5
Its not moving from one to another though is there a short cut on the keyboard for this?
|
|
|
Post by tsh73 on Jan 4, 2020 15:46:10 GMT -5
What could be going wrong here? You are setting focus to disabled control. Enable it first.
|
|
|
Post by Rod on Jan 5, 2020 3:59:10 GMT -5
Try this, the initial focus is set to the first textbox, tabbing will then follow the order the controls were created. This is standard practice for input forms, you press The Tab key to jump to the next textbox. You can use the mouse to reposition the focus. Pressing Enter activates the Accept Entry button and its handler.
[WindowSetup] NOMAINWIN WindowWidth = 485 : WindowHeight = 416 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup]
textbox #main.default1entry, 175, 50, 145, 40 textbox #main.default2entry, 175, 90, 145, 40 textbox #main.default3entry, 175, 130, 145, 40 Stylebits #main.default, _BS_DEFPUSHBUTTON, 0, 0, 0 button #main.default, "Accept Entry", [default], UL, 175, 170, 145, 40 Open "Default Button" for Window as #main #main "trapclose [quit]" #main.default1entry "!setfocus"
'wait for user to press enter or the button #main.default Wait
[default] 'grab the textbox content and process it
[quit] close #main end
Simpler is it not?
|
|
|
Post by metro on Jan 5, 2020 8:24:07 GMT -5
for the input of numeric data I do prefer to be able to press enter you can have both options...
nomainwin textbox #main.tb01, 10, 10, 100, 25 textbox #main.tb02, 10, 40, 100, 25 textbox #main.tb03, 10, 70, 100, 25 textbox #main.tb04, 10, 100, 100, 25 textbox #main.tb05, 10, 130, 100, 25
statictext #main.status, "", 10, 160, 100, 20
button #main.fakeBtn, "", [next_tb], ul, 0, 0, 1, 1 stylebits #main.fakeBtn, _BS_DEFPUSHBUTTON, 0, 0, 0
open "tab or enter between textboxes" for window as #main #main "trapclose [quit]"
#main.fakeBtn "hide" #main.tb01,125.66 #main.tb01, "!selectall" wait
[next_tb] calldll #user32, "GetFocus", _ gotFocus as long
for i = 1 to 5 checkHandle$ = "#main.tb0"; i nextBoxIndex = i+1 if nextBoxIndex > 5 then nextBoxIndex = 1 nextHandle$ = "#main.tb0"; nextBoxIndex
if gotFocus = hwnd(#checkHandle$) then #nextHandle$, "!setfocus" ' #nextHandle$, "!selectall" 'USE to EDIT EXISTING DATA exit for end if next wait
[quit] close #main end
|
|