|
Post by mknarr on Dec 24, 2018 12:36:05 GMT -5
No it's not simple. If I understand you correctly you want to be able to create a number of controls before you open the window. There is no simple way. You can do things with multiple controls after the window is open using Var. Here is a small program I wrote years ago. It's not a great program and doesn't do Combo boxes but can easily be modified to do them.
'GUI Helper written by Jim Brossman maeknarr@yahoo.com 'Released into the public domain 'Version 1.0 1/21/2008 'This program is useful when trying to create multiple controls 'at one time without having to use the copy section in FreeForm. 'Instructions for the program are at the end of the program.
nomainwin WindowWidth = 600 WindowHeight = 800 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) statictext #main, "How Many", 15, 5, 85, 25 textbox #main.tb1, 130, 0, 40, 25 stylebits #main.tb1,_ES_NUMBER,0,0,0 'Set textbox to accept whole numbers only statictext #main, "Length", 15, 40, 85, 25 textbox #main.tb2, 130, 35, 40, 25 stylebits #main.tb2,_ES_NUMBER,0,0,0 statictext #main, "Height", 15, 75, 85, 25 textbox #main.tb3, 130, 70, 40, 25 stylebits #main.tb3,_ES_NUMBER,0,0,0 statictext #main, "Starting X Location", 15, 105, 85, 40 textbox #main.tb4, 130, 105, 40, 25 stylebits #main.tb4,_ES_NUMBER,0,0,0 statictext #main, "Starting Y Location", 15, 142, 85, 40 textbox #main.tb5, 130, 140, 40, 25 stylebits #main.tb5,_ES_NUMBER,0,0,0 statictext #main, "Spacing", 15, 180, 85, 25 textbox #main.tb6, 130, 175, 40, 25 stylebits #main.tb6,_ES_NUMBER,0,0,0 statictext #main, "Window Handle", 15, 215, 110, 25 textbox #main.tb7, 130, 210, 100, 25 button #main.b2,"Create Textboxes",[textboxes], UL, 410, 2, 140, 25 button #main.b1,"Create Buttons",[buttons], UL, 410, 42, 140, 25 button #main.b3,"Create Radiobuttons",[radiobuttons], UL, 410, 82, 140, 25 button #main.b4,"Create Checkboxes",[checkboxes], UL, 410, 122, 140, 25 button #main.b5,"Create Statictext",[statictext], UL, 410, 162, 140, 25 button #main.b6,"Clear All", [clearall],UL, 410, 202, 140, 25 texteditor #main.te, 10, 250, 575, 475
open "GUI Helper" for window_nf as #main print #main, "font Arial 10 Bold" print #main, "trapclose [quit.main]" 'Get handles of textboxes. Needed to make Enter key move between boxes. hTextbox1=hwnd(#main.tb1) hTextbox2=hwnd(#main.tb2) hTextbox3=hwnd(#main.tb3) hTextbox4=hwnd(#main.tb4) hTextbox5=hwnd(#main.tb5) hTextbox6=hwnd(#main.tb6) hTextbox7=hwnd(#main.tb7)
[clearall] for hv=1 to 7 'Clear all text boxes var$="#main."+word$("tb1 tb2 tb3 tb4 tb5 tb6 tb7",hv) #var$ "" next 'Set the number of controls to create. These varibles will allow 'the user to create controls and then create more controls so the 'indexing will be done correctly. tbnumber=1 bnumber=1 rbnumber=1 cbnumber=1 stnumber=1 rownumber=1 'This varible is used in the texteditor to keep 'track of which line to print the output to. print #main.te,"!cls" timer 50, [enterkey] 'Turn timer on so program checks for Enter key presses.
[loop] #main.tb1, "!setfocus" wait
[enterkey] 'Check to see if Enter key was pressed. CallDLL #user32, "GetAsyncKeyState",_VK_RETURN as long,fKeyPress as long if fKeyPress <0 then 'If Enter key is pressed calldll #user32,"GetFocus",textboxHandle as ulong 'Depending on which textbox has focus when Enter key is pressed 'set the focus to the next textbox. select case textboxHandle case hTextbox1 'If textbox 1 has focus, set focus to textbox 2. #main.tb2,"!setfocus" case hTextbox2 #main.tb3,"!setfocus" case hTextbox3 #main.tb4,"!setfocus" case hTextbox4 #main.tb5,"!setfocus" case hTextbox5 #main.tb6,"!setfocus" case hTextbox6 #main.tb7,"!setfocus" case hTextbox7 #main.tb7,"!setfocus" end select end if wait
[textboxes] 'Set control conditions for textboxes. gosub [checkdata] 'Check to see if all textboxes are filled in. if flag then wait 'If all textboxes are not filled in. control$="textbox" 'Name of control. extension$="tb" 'Extension of control. start=tbnumber 'Start set to number of controls desired. gosub [createcontrol] tbnumber=tbnumber+number 'Set number of controls to number already created. goto [loop]
[buttons] 'Set control conditions for buttons. gosub [checkdata] if flag then wait control$="button" extension$="b" start=bnumber gosub [createcontrol] bnumber=bnumber+number goto [loop]
[radiobuttons] 'Set control conditions for radioboxes. gosub [checkdata] if flag then wait control$="radiobutton" extension$="rb" start=rbnumber gosub [createcontrol] rbnumber=rbnumber+number goto [loop]
[checkboxes] 'Set control conditions for checkboxes. gosub [checkdata] if flag then wait control$="checkbox" extension$="cb" start=cbnumber gosub [createcontrol] cbnumber=cbnumber+number goto [loop]
[statictext] 'Set control conditions for statictext. gosub [checkdata] if flag then wait control$="statictext" extension$="st" start=stnumber gosub [createcontrol] stnumber=stnumber+number goto [loop]
[checkdata] 'Retreive data and check to see if all textboxes have been 'filled in before creating any controls. If a textbox is not 'filled in, focus will be set to that textbox. flag=0 'Flag set to 0, a 1 = some textbox is not filled in. #main.tb1, "!contents? number$":number=val(number$) if number$="" then #main.tb1, "!setfocus":flag=1:return #main.tb2, "!contents? length$" if length$="" then #main.tb2, "!setfocus":flag=1:return #main.tb3, "!contents? height$":height=val(height$) if height$="" then #main.tb3, "!setfocus":flag=1:return #main.tb4, "!contents? xlocation$" if xlocation$="" then #main.tb4, "!setfocus":flag=1:return #main.tb5, "!contents? ylocation$":ylocation=val(ylocation$) if ylocation$="" then #main.tb5, "!setfocus":flag=1:return #main.tb6, "!contents? spacing$":spacing=val(spacing$) if spacing$="" then #main.tb6, "!setfocus":flag=1:return #main.tb7, "!contents? windowname$" if windowname$="" then #main.tb7, "!setfocus":flag=1 return
[createcontrol] 'Create controls for a=start to start+number-1 select case extension$ 'Depending on the extension, set conditions. case "b" 'buttons label$=chr$(34)+"button"+str$(a)+chr$(34) 'CHR$(34)=" corner$=", [button"+str$(a)+"Click], UL, " case "rb" 'radiobuttons label$=chr$(34)+"radiobutton"+str$(a)+chr$(34) corner$=", [rb"+str$(a)+"Set], [rb"+str$(a)+"Reset], " case "cb" 'checkboxes label$=chr$(34)+"checkbox"+str$(a)+chr$(34) corner$=", [cb"+str$(a)+"Set], [cb"+str$(a)+"Reset], " case "tb" 'textboxes label$="" corner$="" case "st" 'statictext label$=chr$(34)+"statictext"+str$(a)+chr$(34) corner$=", " end select 'This line creates the text for the control line$=control$+" #"+windowname$+"."+extension$+str$(a)+_ ", "+label$+corner$+xlocation$+", "+str$(ylocation)+", "+length$+", "+height$ print #main.te, "!select ";1;" ";rownumber 'Set row in texteditor. print #main.te, "!insert line$" 'Print to the text editor. rownumber=rownumber+1 'Index row number ylocation=ylocation+height+spacing 'Calculate the next Y location. next return
[quit.main] timer 0 'Turn the timer off. Just good practice. close #main END
[Instructions] 'This program will allow the user to create multiple controls for textboxes, 'buttons, radiobuttons, checkboxes and static text lines. The text that identifies 'the button, statictext, radiobutton or checkboxes will ultimately have to 'be filled in by the user. That can be done in the text editor or when 'pasted to your program. 'The following text boxes will be used to determine how the controls are created. 'How Many - How many controls do you want to create. 'Length - What is the length of the control in pixels. ' Text boxes, buttons and statictext can be any length. ' radiobuttons and checkboxes must be long enough for the text. 'Height - How high do you want the control. Most should be at least 25 pixels 'Starting X location? - This will be the X position of the upper left corner ' of the first control. 'Starting Y Location? - This will be the Y position of the upper left corner ' of the first control. 'Spacing? - This will be the Y spacing between the remaining controls. 'Window Handle - This will be the handle of your window. DO NOT USE THE # SIGN.
'The buttons will create the output for the selected controls and print the text 'to the the texteditor. Each control will be indexed. For example, you can create '5 textbox controls and then 5 statictext controls. You can decide to create '5 more textboxes and they will be indexed correctly except you must change the 'Starting Y Location to reflect the correct Y position. That is the last textbox 'Y location plus the control height plus the spacing. 'After you create some or all of the controls, you can use the Edit menu to Select 'All of the output and then paste into your program. You can also select just some 'of the output and copy and paste just that into your program. You can also change 'the text of the controls before copying. 'The Clear All button will reset all variables and clear the texteditor. If you use 'this button, all indexing will be set to 1.
'I would suggest that a tkn is created and the program be added to the 'Setup - External Programs section so that it is available in the Run section. 'That will make it easy to use the program while writing your program and paste 'output into it.
|
|
|
Post by tsh73 on Dec 26, 2018 14:09:40 GMT -5
In the line with "not easy" See recordEdit$ function See how controls set up - 10 of each and extra get moved off-screen (-1000) or below windowHeight
'record edit 'tsh73 Aug 2016 'v.01 - initial window 'v.02 - functionized 'v.03 - call from window (not from mainwin) 'v.04 - variable header size, change-able text size (txtWidthChars) 'v.05 - validators ' i integer ' n number ' i and n supports range: ' n N, means >=N ' n ,M means <=M ' n N,M means >=N and <=M ' s N string width 'v.05.1 - data validator ' d dataMask, like dd.mm.yyyy or mm/dd/yyyy or yyyy-mm-dd 'v.06 - validators off (add from Version 5 if needed), add selection from list instead
'input - key-value pair list 'for now, list of head$ and body$
head$ = "FIO|Street|Building|Flat" body$ = "John Smit|Baker St.|26|2.5" valid$ = "|s 10|i|n 1,10" global listList$ 'need it in a handler listList$="James Moriarty¦Sherlock Holmes¦dr. Watson|Reichenbach Falls¦Baker St."
'----------------------------------------
nomainwin gosub [getSlack]
WindowWidth = 536 WindowHeight = 520
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "head list", 14, 6, 144, 20 textbox #main.head, 22, 26, 504, 25 statictext #main.statictext3, "data list", 14, 56, 144, 20 textbox #main.data, 22, 76, 504, 25 statictext #main.statictext4, "validator list", 14, 106, 144, 20 textbox #main.valid, 22, 126, 504, 25 statictext #main.statictext5, "list of lists", 14, 156, 144, 20 textbox #main.listList, 22, 176, 504, 25 button #main.button6, "Run recordEdit", [button6Click], UL, 14, 211, 122, 25 groupbox #main.groupbox7, " Log ", 14, 241, 512, 225 texteditor #main.log, 30, 261, 480, 195 menu #main, "Edit"
open "recordEdit test" for window as #main #main "trapclose [quit.main]"
#main "font arial 10"
#main.head head$ #main.data body$ #main.valid valid$ #main.listList listList$
wait
[quit.main] Close #main END
[button6Click] #main.head "!contents? head$" #main.data "!contents? body$" #main.valid "!contents? valid$" #main.listList "!contents? listList$" #main.log "================" #main.log "head$: ";head$ #main.log "body$: ";body$ res$=recordEdit$(head$, body$, valid$) #main.log "----------------" if body$ = res$ then #main.log "Nothing changed" else body$ = res$ #main.data body$ #main.log "body$: ";body$ end if wait
'--------------------------------------------------- [getSlack] WindowWidth=200:WindowHeight=200 open "" for graphics_nsb as #t:#t,"home;posxy x y":close#t global slackX,slackY slackX=WindowWidth-2*x:slackY=WindowHeight-2*y return
'========================================
function recordEdit$(head$, body$, valid$) item$="*" i = 0 maxLen=0 while item$ <> "" i = i+1 item$ = word$(head$, i, "|") if len(item$)>maxLen then maxLen=len(item$) wend nItems =i-1 maxItems = 10 if nItems > maxItems then notice "Attention!"+chr$(13)+_ "There is "; nItems ;" items passed to recordEdit window." +chr$(13)+_ "This tool allows only for "; maxItems ;" items" +chr$(13)+_ "If you want to avoid data loss press Cancel in recordEdit window." nItems = maxItems end if
recordEdit$ = body$ 'for case of cancel / closing window
'calc widths 'needs monospased font of known size font$="font courier_new 10" charWidth = 8 'for this font. Might depend on DPI etc 'stWidthChars = 15 stWidthChars = maxLen stWidth=(stWidthChars+0.5)*charWidth txtWidthChars = 30 txtWidth = (txtWidthChars+0.5)*charWidth global txtPos 'for popup position txtPos = 14+stWidth+8 grPos = txtPos+txtWidth'+10 grWidth = 20 btnPos = grPos+grWidth+10 btnWidth=122
WindowWidth = 8+btnPos+btnWidth+10
addLine = 0: if nItems > 3 then addLine = nItems -3 pixPerLine=35 WindowHeight = 150 + pixPerLine*addLine
UpperLeftX=1 UpperLeftY=1
dim nl(maxItems) 'no list for i = 1 to maxItems nl(i)=( word2$(listList$, i)="" ) next
statictext #recordEdit.hd1, "StaticText Caption1", 14, 15, stWidth, 20 textbox #recordEdit.tb1, txtPos-1000*(1>nItems), 10, txtWidth, 25 graphicbox #recordEdit.gr1, grPos-1000*(1>nItems)-1000*nl(1), 10, grWidth, 25
'+pixPerLine down statictext #recordEdit.hd2, "StaticText Caption2", 14, 2*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb2, txtPos-1000*(2>nItems), 2*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr2, grPos-1000*(2>nItems)-1000*nl(2), 2*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd3, "StaticText Caption3", 14, 3*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb3, txtPos-1000*(3>nItems), 3*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr3, grPos-1000*(3>nItems)-1000*nl(3), 3*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd4, "StaticText Caption3", 14, 4*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb4, txtPos-1000*(4>nItems), 4*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr4, grPos-1000*(4>nItems)-1000*nl(4), 4*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd5, "StaticText Caption3", 14, 5*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb5, txtPos-1000*(5>nItems), 5*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr5, grPos-1000*(5>nItems)-1000*nl(5), 5*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd6, "StaticText Caption3", 14, 6*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb6, txtPos-1000*(6>nItems), 6*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr6, grPos-1000*(6>nItems)-1000*nl(6), 6*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd7, "StaticText Caption3", 14, 7*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb7, txtPos-1000*(7>nItems), 7*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr7, grPos-1000*(7>nItems)-1000*nl(7), 7*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd8, "StaticText Caption3", 14, 8*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb8, txtPos-1000*(8>nItems), 8*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr8, grPos-1000*(8>nItems)-1000*nl(8), 8*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd9, "StaticText Caption3", 14, 9*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb9, txtPos-1000*(9>nItems), 9*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr9, grPos-1000*(9>nItems)-1000*nl(9), 9*pixPerLine-25, grWidth, 25
statictext #recordEdit.hd10, "StaticText Caption3", 14, 10*pixPerLine-20, stWidth, 20 textbox #recordEdit.tb10, txtPos-1000*(10>nItems), 10*pixPerLine-25, txtWidth, 25 graphicbox #recordEdit.gr10, grPos-1000*(10>nItems)-1000*nl(10), 10*pixPerLine-25, grWidth, 25
button #recordEdit.Default, "OK", [btnOKClick], UL, btnPos, 11, btnWidth, 25 button #recordEdit.btnCancel, "Cancel", [btnCancelClick], UL, btnPos, 46, btnWidth, 25 button #recordEdit.btnRevert, "Revert", [btnRevertClick], UL, btnPos, 81, btnWidth, 25
open "recordEdit" for dialog_nf_modal as #recordEdit print #recordEdit, "trapclose [recordEditQuit]" print #recordEdit, font$
'fill data 'remove extra fields for i = nItems+1 to maxItems handle$="#recordEdit.hd";i #handle$ "" handle$="#recordEdit.tb";i #handle$ "!disable" next for i = 1 to nItems if nl(i)=0 then handle$="#recordEdit.tb";i #handle$ "!disable" handle$="#recordEdit.gr";i #handle$ "down; fill buttonface" #handle$ "size 1; color black; north; turn 90" for j = 0 to 4 #handle$ "place ";grWidth/2-j;" ";25/2+3-j #handle$ "go ";2*j next #handle$ "flush" #handle$ "when leftButtonDown grBtnClick" end if next
[revert] for i = 1 to nItems handle$="#recordEdit.hd";i item$=word2$(head$, i) #handle$ space$(stWidthChars-len(item$)); item$ handle$="#recordEdit.tb";i item$=word2$(body$, i) #handle$ item$ next
wait
[recordEditQuit] Close #recordEdit exit function
[btnOKClick] retStr$="" notValidMsg$="" for i = 1 to nItems handle$="#recordEdit.tb";i item$=word2$(head$, i) #handle$ "!contents? value$" retStr$=retStr$+"|"+value$
validator$=word2$(valid$, i) if validator$<>"" then validRes$=notValid$(item$,value$,validator$) if validRes$<>"" then notValidMsg$=notValidMsg$+chr$(13)+validRes$ end if end if next if notValidMsg$<>"" then notice "Not valid";notValidMsg$ wait end if retStr$ = mid$(retStr$, 2) recordEdit$ = retStr$ goto [recordEditQuit] wait
[btnCancelClick] goto [recordEditQuit] wait
[btnRevertClick] goto [revert] wait end function
sub grBtnClick handle$, dummyX, dummyY ' popup window ----------------------- ctrlIndex = val(mid$(handle$, len("#recordEdit.gr")+1)) POPUPret$="" menu$=word2$(listList$, ctrlIndex) if trim$(menu$)="" then exit sub nPopup = countWords(menu$, "¦") dim popup$(nPopup) for i = 1 to nPopup popup$(i) = word$(menu$,i,"¦") next
'for "font courier_new 10" POPUPcharWidth=8 POPUPcharHeight=16
maxlen = 0 for i = 1 to nPopup if maxlen<len(popup$(i)) then maxlen=len(popup$(i)) next listWidth=maxlen*POPUPcharWidth + 25 'scroll bar listHeight = (nPopup+.5)*POPUPcharHeight
WindowWidth = listWidth + slackX WindowHeight = listHeight + slackY
UpperLeftX =txtPos '1 'UpperLeftY =1 pixPerLine=35 UpperLeftY =ctrlIndex*pixPerLine-25 listbox #POPUP1.listbox1, popup$(, [POPUP1listbox1DoubleClick], 0, 0, listWidth, listHeight BUTTON #POPUP1.default, "offscrenSelect", [POPUP1listbox1DoubleClick], UL, -100, -100 'offscren! open "Select one" for dialog_modal as #POPUP1 print #POPUP1, "trapclose [POPUP1quit]"
#POPUP1.listbox1, "font courier_new 10" #POPUP1.listbox1 "selectindex 1" wait
[POPUP1quit] 'ESC pressed POPUPret$="" goto [POPUP1return]
[POPUP1listbox1DoubleClick] #POPUP1.listbox1, "selection? sel$" #POPUP1.listbox1, "selectionindex? popupIndex1" POPUPret$ = popup$(popupIndex1) handle$="#recordEdit.tb";ctrlIndex #handle$ POPUPret$ [POPUP1return] close #POPUP1 exit sub end sub
function countWords(objStr$, delim$) token$ = "?" while token$ <> "" countWords = countWords + 1 token$ = word$(objStr$, countWords, delim$) wend countWords = countWords - 1 end function
function word2$(list$, i) word2$ = word$(list$, i, "|") if word2$="|" then word2$="" 'empty end function
function notValid$(head$,item$,validator$) notValid$ = "" 'stub, says always valid end function
|
|