|
Post by patrice on Feb 18, 2019 4:39:17 GMT -5
Hello I have five textbox aligned vertically and I would like that when you press one of the arrow keys (up, down) the cursor move to another textbox
could you help me ?
|
|
|
Post by Rod on Feb 18, 2019 6:28:42 GMT -5
Well this might not be the correct approach. To explain, text box controls are designed to interact with the mouse. Click in a textbox and Windows creates an insertion point exactly where you clicked. This aids editing. Other way to move between text boxes is to press Tab. This moves the cursor to the next text box. If there is text already in there Windows highlights that text, it will be replaced by whatever you type unless you click with the mouse to create an insertion point. You can quickly Tab round text box controls. This is how folks are used to dealing with text boxes. They are unlikely to use the cursor keys to move between text boxes, you will need to make that clear.
So what sort of text manipulation are you planning? Fresh each time or editing?
nomainwin
textbox #t.txt1, 20, 40, 260, 25 textbox #t.txt2, 20, 70, 260, 25 textbox #t.txt3, 20, 100, 260, 25 textbox #t.txt4, 20, 130, 260, 25 textbox #t.txt5, 20, 160, 260, 25 WindowWidth = 350 : WindowHeight = 290 open "Simple text box use" for window as #t #t "trapclose [quit]"
wait
[quit] close #t end
|
|
|
Post by patrice on Feb 18, 2019 6:47:50 GMT -5
in each textbox, I have a numeric value corresponding to a chemical element it's easier to switch from one textbox to another by simply clicking the down key ...
|
|
|
Post by patrice on Feb 18, 2019 7:13:36 GMT -5
It works when I press Tab. Thanks
|
|
|
Post by Rod on Feb 18, 2019 11:44:37 GMT -5
Perhaps a listbox is the right control if you are simply letting the user choose a limited number of elements. So Oxygen might allow one or two to be chosen Carbon one to eight. I am assuming you are building molecules.
|
|
|
Post by mknarr on Feb 18, 2019 11:54:24 GMT -5
Rather long but I use the following code in a lot of Dialog_modal windows. Pressing the enter key moves the cursor to the next text box.'This will work in either a dialog-modal or window window nomainwin WindowWidth = 300 WindowHeight = 450 BackgroundColor$ = "buttonface" ForegroundColor$ = "black" textbox #sample.tb1,15,122,200,25 textbox #sample.tb2,15,152,200,25 textbox #sample.tb3,15,182,200,25 textbox #sample.tb4,15,212,200,25
open "Enter Key sample " for window as #sample #sample, "font arial 10 " #sample, "trapclose [quit]" hTextbox1=hwnd(#sample.tb1) 'You need the handle of each text box hTextbox2=hwnd(#sample.tb2) hTextbox3=hwnd(#sample.tb3) hTextbox4=hwnd(#sample.tb4) #sample.tb1,"!setfocus" timer 50,[samplekey] wait
[samplekey] 'Trap enter key. CallDLL #user32, "GetAsyncKeyState",_VK_RETURN as long,fKeyPress as long if fKeyPress <0 then 'If no key is pressed calldll #user32,"GetFocus",textboxHandle as ulong select case textboxHandle 'if the enter key is pressed case hTextbox1 'and the cursor was in textbox one #sample.tb2,"!setfocus" 'the set the focus to textbox 2 case hTextbox2 #sample.tb3,"!setfocus" case hTextbox3 #sample.tb4,"!setfocus" case hTextbox4 goto [quit] 'Your calculations go here or the program continues. end select end if wait
[quit] close #sample end
|
|
|
Post by metro on Feb 18, 2019 18:14:26 GMT -5
another example along the same lines as mknarr you can TAB or ENTER between textboxes
' --- start of code (watch for line wraps)
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.fakeTab, "", [next_tb], ul, 0, 0, 1, 1 stylebits #main.fakeTab, _BS_DEFPUSHBUTTON, 0, 0, 0
open "tab or enter between textboxes" for window as #main #main "trapclose [quit]"
#main.fakeTab "hide" ' #main.tb_01, "!setfocus" print #main.tb01, "!setfocus" 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" exit for end if next wait
[quit] close #main end
|
|
|
Post by mpranger on Oct 30, 2019 17:00:06 GMT -5
Is there a way to use a textbox but have it display string and or numeric variables instead of user input? Or if a textbox isn't the right thing, what else would work?
|
|
|
Post by metro on Oct 30, 2019 18:16:31 GMT -5
Is there a way to use a textbox but have it display string and or numeric variables instead of user input? Or if a textbox isn't the right thing, what else would work? lots of tinkering explained here
|
|
|
Post by Rod on Oct 31, 2019 3:27:00 GMT -5
Its often easy to forget how confusing Liberty can be for beginners. Yes it is easy to print text or variables to a textbox or texteditor. Just use its name and tell it what to print. Lets say you created a textbox called #main.tb
print #main.tb, "Hello"
Here I print literal strings and variables to textboxes
nomainwin
textbox #t.txt1, 20, 40, 260, 25 textbox #t.txt2, 20, 70, 260, 25 textbox #t.txt3, 20, 100, 260, 25 textbox #t.txt4, 20, 130, 260, 25 textbox #t.txt5, 20, 160, 260, 25 WindowWidth = 350 : WindowHeight = 290 open "Simple text box use" for window as #t #t "trapclose [quit]"
'the command "print" is optional, you can just use the name of the textbox control #t.txt1, "Hello" #t.txt2, 123 a=456 #t.txt3, a a$="See its really easy" #t.txt4,a$
wait
[quit] close #t end
|
|
|
Post by alincon on Oct 31, 2019 9:26:51 GMT -5
Also, look at using Statictext to display text that will not change.
r.m.
|
|
|
Post by mpranger on Oct 31, 2019 12:50:55 GMT -5
Also, look at using Statictext to display text that will not change. r.m. Yes. That's even better. It's exactly what I want. Only thing is I already have a window open. I want it to label a row of radio buttons but not open a new window. I'll experiment and see what I can do with this. Thanks!
|
|
|
Post by mpranger on Oct 31, 2019 12:55:29 GMT -5
OK I figured it out. Thanks again.
|
|
|
Post by Rod on Oct 31, 2019 13:25:14 GMT -5
I hope you found groupbox, this is straight out the help file and labels both the button group and the radiobuttons themselves.
'demonstrate radiobuttons with branch label event handlers nomainwin WindowWidth = 520 WindowHeight = 220 groupbox #cfg, "Confirm File Operations:", 240, 20, 200, 140 radiobutton #cfg.Aalways, "Always", [alwaysConfirm], [nil], 260, 45, 130, 20 radiobutton #cfg.AwhenReplacing, "When Replacing", _ [whenReplacingConfirm], [nil], 260, 70, 130, 20 radiobutton #cfg.Anever, "Never", [neverConfirm], [nil], 260, 95, 130, 20 groupbox #cfg, "Confirm Close Operations:", 20, 20, 200, 140 radiobutton #cfg.always, "Always", [alwaysClose], [nil], 40, 45, 130, 20 radiobutton #cfg.whenReplacing, "When Replacing", _ [whenReplacingClose], [nil], 40, 70, 130, 20 radiobutton #cfg.never, "Never", [neverClose], [nil], 40, 95, 130, 20 button #cfg, " &OK ", [cfgOk], UL, 450, 30 open "Action Confirmation - Setup" for dialog as #cfg print #cfg, "trapclose [cfgOk]" print #cfg.Anever, "set" print #cfg.never, "set" wait
[alwaysConfirm] status$ = "Always Confirm" wait
[whenReplacingConfirm] status$ = "When Replacing Confirm" wait
[neverConfirm] status$ = "Never Confirm" wait
[alwaysClose] cstatus$ = "Always Close" wait
[whenReplacingClose] cstatus$ = "When Replacing Close" wait
[neverClose] cstatus$ = "Never Close" wait
[cfgOk] msg$ = status$ + chr$(13) + cstatus$ + chr$(13) msg$ = msg$ + "Save this configuration?" confirm msg$ ; answer$ 'perform some sort of save for config here close #cfg end
[nil] wait
|
|
|
Post by mpranger on Nov 1, 2019 8:44:18 GMT -5
Yes Rod. With your earlier assistance. I got that. Somehow I kinda figured out the groups. I only ask for help when I'm stumped. Originally I only got LB to do one thing and that was to make a front end with radio buttons to create a data entry program for a spreadsheet. That works perfectly for me. But it was so much fun I started tinkering with using LB to do everything and eliminate the spreadsheet. So that's what I'm doing now. I cut and pasted snippets and changed them to suit me. But if you saw the code you might be horrified. I'm a little weak on using arrays. Instead I have made these wide ranging loops. It has one overall benefit and that is that it works. I appreciate the help a lot. Greg
|
|