|
Post by pablosl on Nov 22, 2023 12:23:23 GMT -5
Hi,
Can listboxes have columns separated by pixels? I know of trick using fixed fonts and separated by spaces (not what I want)
Thanks You.
-Pablo
|
|
|
Post by Rod on Nov 22, 2023 14:40:32 GMT -5
A list box lists text, usually the vertical separation is driven by font size. But perhaps we are talking horizontal separation. Code would help since I don’t understand the question.
|
|
|
Post by tsh73 on Nov 22, 2023 14:53:26 GMT -5
Multicolumn listbox looks like this (from Visual Studio) Column just wraps up to several rows instead of scrolling. You hardly want this Rather you wont something like grid? Some pictures might help.
|
|
|
Post by metro on Nov 22, 2023 18:12:27 GMT -5
not sure if this helps, EDIT...oops uses spaces
NoMainWin WindowWidth = 800 WindowHeight = 600 dim rowdata$(10000) rowdata$(1)="Wednesday";chr$(9);" 7.30" ;chr$(9); " 18.00 ";chr$(9);" 8 ";chr$(9);" 3.0 ";chr$(9); "1.5" rowdata$(2)="Thursday ";chr$(9);" 8.30" ;chr$(9); " 17.00 ";chr$(9);" 8.5 ";chr$(9);" 3.0 ";chr$(9); "1.5" rowdata$(3)="Friday ";chr$(9);" 7.30" ;chr$(9); " 18.00 ";chr$(9);" 8 ";chr$(9);" 3.0 ";chr$(9); "1.5" statictext #exc.stxt1 " DAY START END NT T1/2 2T HOURS",6,13,700,25 StyleBits #exc.list, _LBS_USETABSTOPS, 0, 0, 0 ListBox #exc.list, rowdata$(), [Wait], 6, 36, 450, 250 Button #exc.btnClose, "Close", [Quit], UL, (WindowWidth-8-50)/2, 500, 50, 25 StyleBits #exc, _DS_CENTER, 0, 0, 0
'============================================================= OPEN WINDOW Open "LBS_USETABSTOPS Demo" For window As #exc print #exc.list, "font times_new_roman 10" #exc.stxt1, "!font times_new_roman 10 bold" #exc "TrapClose [Quit]"
' Get handle of list box hwnd = HWnd(#exc.list)
' Build a struct to act as an array of int's. Struct lParam,_ cx1 As Long,_ cx2 As Long,_ cx3 As Long,_ cx4 As Long,_ cx5 As Long,_ cx6 As Long
' Set tab stops. Since this is in a dialog, these are in dialog units. lParam.cx1.struct = 10 'distance colum 1 lParam.cx2.struct = 45'distance colum 2 lParam.cx3.struct = 70 'distance colum 3 lParam.cx4.struct = 100 'distance colum 4 lParam.cx5.struct = 130 'distance colum 5 lParam.cx6.struct = 160 'distance colum 6
' set the number of tab stops in the lParam structure TabCount=6
CallDLL #user32, "SendMessageA", _ hwnd As ULong, _LB_SETTABSTOPS As ULong, _ TabCount As Long, lParam As Struct, _ ret As Long
[main] #exc.list, "reload" #exc.list "singleclickselect [selectlist]" wait
[Wait] Wait
[Quit] Close #exc End
[startload] token$ = "?" while token$ <> "" index = index + 1 token$ = word$(rowdat$, index) ans$(index)= token$ wend ' X=X+1
goto [startload]
' next [finish2] ' close #loadcompany
'set timer for checking selected listview row ' timer 500, [callsub]
[main.inputLoop] 'wait here for input event
wait
' ==================Branch for selected list.
[selectlist] #exc.list "selection? item$" #exc.list, "selectionindex? i" notice "selected ";item$;" INDEX ";i wait
|
|
|
Post by Rod on Nov 23, 2023 8:38:12 GMT -5
The only way to place text at a pixel position that I know of is to use a graphicbox and mimic a listbox. Probably too much work since the fixed font and spaces method delivers a reasonable solution.
|
|
|
Post by pablosl on Nov 23, 2023 9:44:44 GMT -5
Ok thank you very much to all.
-Pablo
|
|
|
Post by mknarr on Nov 23, 2023 10:06:00 GMT -5
'** 24/05/2003 15:55:47 '** An implementation of multiple columns in a standard listbox ' Features: four functions for left, center or right alignment and currency format. ' Use of a hidden graphics box and the stringwidth function to calculate correct padding ' independent of font selected. ' Open source, feel free to use if functions suit your needs. 'Bill Christiansen 'nomainwin [WindowSetup] 'NOMAINWIN WindowWidth = 570 : WindowHeight = 600 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) width1 = 195 width2 = 195 width3 = 100 [ControlSetup] Menu #main, "&File" , "E&xit", [quit] graphicbox #main.graphicbox1, 1, 1, 1, 1 statictext #main.st1, "Choose a font and column alignment", 15, 5, 300, 20 statictext #main.st2, "Sort by column 1 or 2 by clicking header", 15, 150, 300, 20 button #main.button1, "Left",[button1.click],UL, 100, 70, 105, 25 button #main.button2, "Center",[button2.click],UL, 210, 70, 105, 25 button #main.button3, "Right",[button3.click],UL, 320, 70, 105, 25 button #main.button4, "Font",[button4.click],UL, 210, 40, 105, 25 button #main.col1, "Food Group +",[col1.click],UL, 15, 180, width1, 22 button #main.col2, "Item +",[col2.click],UL, 15+width1, 180, width2, 22 button #main.col3, "Price / kg",[col3.click],UL, 15+width1+width2,180, width3+40, 22 listbox #main.list1, list$(,[list1.click], 15, 199, 530, 300 Open "Multi-Column Listbox Demo" for Window as #main print #main, "trapclose [quit]" print #main, "font ms_sans_serif 10" col1$ = "DES" 'initialise sort variable to descending col2$ = "DES" 'will change to "ASC" when column header clicked Dim data$(10,3) Dim list$(10) data$(1,1) = "Fruit" :data$(1,2) = "bananas" : data$(1,3) = "2.39" data$(2,1) = "Fruit" :data$(2,2) = "oranges" : data$(2,3) = "4.49" data$(3,1) = "Fruit" :data$(3,2) = "apples" : data$(3,3) = "2.49" data$(4,1) = "Vegetable" :data$(4,2) = "potatoes" : data$(4,3) = "2.29" data$(5,1) = "Vegetable" :data$(5,2) = "carrots" : data$(5,3) = "1.99" data$(6,1) = "Vegetable" :data$(6,2) = "tomatoes" : data$(6,3) = "7.79" data$(7,1) = "Meat" :data$(7,2) = "ground beef" : data$(7,3) = "10.99" data$(8,1) = "Meat" :data$(8,2) = "chicken breast" : data$(8,3) = "17.49" data$(9,1) = "Meat" :data$(9,2) = "Ham, fat free" : data$(9,3) = "21.50" count = 9 format$ = "left" chosenFont$ = "Arial 14 italic" [FillList] listFont$ = "font " + chosenFont$ print #main.list1, listFont$ for i = 1 to count a$ = data$(i,1) b$ = data$(i,2) c$ = data$(i,3) c$ = CurrencyFormatStr$(c$,listFont$,width3) if format$ = "left" then a$ = LeftFormatStr$(a$,listFont$,width1) b$ = LeftFormatStr$(b$,listFont$,width2) list$(i) = a$ + b$ + c$ end if if format$ = "center" then a$ = CenterFormatStr$(a$,listFont$,width1) b$ = CenterFormatStr$(b$,listFont$,width2) list$(i) = a$ + b$ + c$ end if if format$ = "right" then a$ = RightFormatStr$(a$,listFont$,width1) b$ = RightFormatStr$(b$,listFont$,width2) list$(i) = a$ + b$ + c$ end if next print #main.list1, "reload" [loop] Wait [quit] close #main : END [button1.click] format$ = "left" goto [FillList] [button2.click] format$ = "center" goto [FillList] [button3.click] format$ = "right" goto [FillList] [button4.click] 'open a font dialog currentFont$ = mid$(listFont$,6) fontdialog currentFont$, chosenFont$ if chosenFont$ = "" then goto [loop] goto [FillList] [col1.click] select case col1$ case "ASC" sort data$(), 1, count , 1 print #main.col1, "Food Group +" col1$ = "DES" case "DES" sort data$(),count,1, 1 print #main.col1, "Food Group -" col1$ = "ASC" end select goto [FillList] [col2.click] select case col2$ case "ASC" sort data$(), 1, count , 2 print #main.col2, "Item +" col2$ = "DES" case "DES" sort data$(),count,1, 2 print #main.col2, "Item -" col2$ = "ASC" end select goto [FillList] [col3.click] goto [loop] [list1.click] print #main.list1, "selection? selected$" print selected$ goto [loop] Function LeftFormatStr$(a$,listFont$,width) print #main.graphicbox1, listFont$ 'give hidden graphics box the current font onePad$ = " " print #main.graphicbox1, "stringwidth? onePad$ PadWidth" 'find out how may pixels in a space print #main.graphicbox1, "stringwidth? a$ FieldWidth" 'find out how many pixels in the string padNum = (width-FieldWidth)/PadWidth if padNum - int(padNum) >= 0.5 then padNum = padNum + 1 'calculate padding rounded to whole character padNum = int(padNum) if FieldWidth > width then 'reduce size of string if it's bigger than field padNum = 0 while FieldWidth > width length = len(a$) - 1 a$ = left$(a$,length) print #main.graphicbox1, "stringwidth? a$ FieldWidth" wend end if if padNum = 0 then [noPad] a$ = a$ + space$(padNum) [noPad] LeftFormatStr$ = a$ end function Function RightFormatStr$(a$,listFont$,width) print #main.graphicbox1, listFont$ onePad$ = " " print #main.graphicbox1, "stringwidth? onePad$ PadWidth" print #main.graphicbox1, "stringwidth? a$ FieldWidth" padNum = (width-FieldWidth)/PadWidth if padNum - int(padNum) >= 0.5 then padNum = padNum + 1 padNum = int(padNum) if FieldWidth > width then padNum = 0 while FieldWidth > width length = len(a$) - 1 a$ = left$(a$,length) print #main.graphicbox1, "stringwidth? a$ FieldWidth" wend end if if padNum = 0 then [noPad] a$ = space$(padNum) + a$ [noPad] RightFormatStr$ = a$ end function Function CenterFormatStr$(a$,listFont$,width) print #main.graphicbox1, listFont$ onePad$ = " " print #main.graphicbox1, "stringwidth? onePad$ PadWidth" print #main.graphicbox1, "stringwidth? a$ FieldWidth" padNum = (width-FieldWidth)/PadWidth padNum = padNum/2 padNum = int(padNum) if FieldWidth > width then padNum = 0 while FieldWidth > width length = len(a$) - 1 a$ = left$(a$,length) print #main.graphicbox1, "stringwidth? a$ FieldWidth" wend end if if padNum = 0 then [noPad] a$ = space$(padNum) + a$ + space$(padNum) [noPad] CenterFormatStr$ = a$ end function Function CurrencyFormatStr$(a$,listFont$,width) print #main.graphicbox1, listFont$ onePad$ = " " a=val(a$) c$ = "$" + Using("####.##",a) print #main.graphicbox1, "stringwidth? onePad$ PadWidth" print #main.graphicbox1, "stringwidth? c$ FieldWidth" padNum = (width-FieldWidth)/PadWidth if padNum - int(padNum) >= 0.5 then padNum = padNum + 1 padNum = int(padNum) if FieldWidth > width then padNum = 0 while FieldWidth > width length = len(a$) - 1 a$ = right$(a$,length) print #main.graphicbox1, "stringwidth? a$ FieldWidth" wend end if a=val(a$) CurStr$ = space$(padNum) + "$" + Using("####.##",a) CurrencyFormatStr$ = CurStr$ End Function
|
|