Page 1 of 1
ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 1:31 am
by IdeasVacuum
So, found some code on the forum (
Drop Height ) that does have an effect on the combo drop-down height, but it is not accurate. Also, it does not work at all if the combo item height is set:
Code: Select all
Enumeration
#Win
#Panel
#Scroll
#Container
#Container2
#Combo
EndEnumeration
LoadFont(iFont18.i, "Arial", 18)
If OpenWindow(#Win, 0, 0, 500, 400, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#Win, RGB(255,200,255))
SetGadgetFont(#PB_Default, FontID(iFont18))
PanelGadget(#Panel, 5, 5, 490, 390)
AddGadgetItem(#Panel, 0, "Tab 0")
ScrollAreaGadget(#Scroll, 5, 5, 470, 360, 600, 500, 20, #PB_ScrollArea_BorderLess)
ContainerGadget(#Container, 10, 10, 280, 80)
SetGadgetColor(#Container, #PB_Gadget_BackColor, RGB(150,255,200))
ComboBoxGadget(#Combo, 10, 10, 260, 50) ;, #CBS_NOINTEGRALHEIGHT)
SendMessage_(GadgetID(#Combo), #CB_SETITEMHEIGHT, 0, 50)
;Max Combo drop-down height measured from Combo Y ;w ;h
MoveWindow_(GetWindow_(GadgetID(#Combo), #GW_CHILD), 0, 0, 250, 250, #True)
For a = 0 To 50
AddGadgetItem(#Combo, -1,"ComboBox Item " + Str(a))
Next
SetGadgetState(#Combo, 0)
CloseGadgetList()
ContainerGadget(#Container2, 10, 100, 280, 240)
SetGadgetColor(#Container2, #PB_Gadget_BackColor, RGB(200,255,150))
CloseGadgetList()
CloseGadgetList()
AddGadgetItem(#Panel, 1, "Tab 1")
CloseGadgetList()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Using MoveWindow_ is of course a work-around. Perhaps it worked better on XP than it does on Win7.
Any ideas? I think I may need to go back to PlanB and use a toolwindow-button-ListIcon combination........
Edit: Snippet was missing CloseGadgetList() for the ScrollArea gadget

Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 12:50 pm
by Fluid Byte
You forgot to set the style flag:
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 1:38 pm
by IdeasVacuum
I had already tried that flag - the result is a 1-row drop down, I want to have a drop down where the height max does not take it outside of the parent window, but not unnecessarily short.
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 2:07 pm
by IdeasVacuum
Another issue is that when the height of the combo button is increased, the text is not centered vertically:
Code: Select all
ComboBoxGadget(#Combo, 10, 10, 260, 60)

Too ugly!
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 2:33 pm
by RASHAD
Hi
Code: Select all
Enumeration
#Win
#Panel
#Scroll
#Container
#Container2
#Combo
EndEnumeration
Global Text$,Brush,Brush_2
Text$ = Space(#MAX_PATH)
LoadFont(iFont18.i, "Arial", 18)
Brush = CreateSolidBrush_($FADC72)
Brush_2 = CreateSolidBrush_($99FEFA)
Procedure WndProc(hWnd, uMsg, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_DRAWITEM
*DRAWITEM.DRAWITEMSTRUCT = lParam
If *DRAWITEM\CtlType = #ODT_COMBOBOX
SetBkMode_(*DRAWITEM\hDC, #TRANSPARENT)
If *DRAWITEM\ItemState & #ODS_FOCUS
FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush)
Else
FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush_2)
EndIf
SendMessage_(*DRAWITEM\hwndItem,#CB_GETLBTEXT,*DRAWITEM\itemID, @Text$)
SetTextColor_(*DRAWITEM\hDC, $0)
*DRAWITEM\rcItem\left = 8
DrawText_(*DRAWITEM\hDC,@Text$,Len(Text$),*DRAWITEM\rcItem, #DT_SINGLELINE | #DT_VCENTER )
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(#Win, 0, 0, 500, 400, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowCallback(@WndProc())
SetWindowColor(#Win, RGB(255,200,255))
SetGadgetFont(#PB_Default, FontID(iFont18))
PanelGadget(#Panel, 5, 5, 490, 390)
AddGadgetItem(#Panel, 0, "Tab 0")
ScrollAreaGadget(#Scroll, 5, 5, 480, 390, 600, 500, 20, #PB_ScrollArea_BorderLess)
ContainerGadget(#Container, 10, 10, 280, 80)
SetGadgetColor(#Container, #PB_Gadget_BackColor, RGB(150,255,200))
ComboBoxGadget(#Combo, 10, 10, 260, 50,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS|#CBS_NOINTEGRALHEIGHT)
SendMessage_(GadgetID(#Combo), #CB_SETITEMHEIGHT, 0, 50)
dLh = FindWindow_("ComboLBox",0)
MoveWindow_(dlh , 0, 0, 250, 250, #True)
For a = 0 To 50
AddGadgetItem(#Combo, -1,"ComboBox Item " + Str(a))
Next
SetGadgetState(#Combo, 0)
CloseGadgetList()
ContainerGadget(#Container2, 10, 100, 280, 235)
SetGadgetColor(#Container2, #PB_Gadget_BackColor, RGB(200,255,150))
CloseGadgetList()
OpenGadgetList(#Panel)
AddGadgetItem(#Panel, 1, "Tab 1")
CloseGadgetList()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 2:35 pm
by Fluid Byte
IdeasVacuum wrote:I had already tried that flag - the result is a 1-row drop down
Which is correct since this returns zero:
Code: Select all
GetWindow_(GadgetID(#Combo), #GW_CHILD)
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 7:14 pm
by IdeasVacuum
It seems the need for containers within containers can potentially have an adverse affect on standard controls, but this is only witnessed when there are a lot of controls.
Rashad, what you have beautifully coded there is exactly how I want the combos to work and how I have defined a 'hand made' effort. My alternative design is a bit heavy, it needs 4 gadgets and a border-less window, but does not need Win API. I'm trying to keep the use of API to a minimum so that producing code for Android, via Spider Basic, is easier. So, decisions decisions.........
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 8:57 pm
by RASHAD
Hi IdeasVacuum
Next is a hand made combo
The CanvasGadget() is very flexible you can adapt it for your needs
Good luck
Code: Select all
LoadFont(0,"Tahoma",12)
If OpenWindow(0, 0, 0, 270, 305, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0,10,10,250,30,#PB_Container_Flat)
SetGadgetColor(0,#PB_Gadget_BackColor,$BEFEBC)
TextGadget(1,5,3,200,20,"ComboBox Item " + Str(1))
SetGadgetColor(1,#PB_Gadget_BackColor,$BEFEBC)
SetGadgetFont(1,FontID(0))
ButtonGadget(2,220,-1,30,30,"Y")
CloseGadgetList()
ScrollAreaGadget(5,10,40,250,250,230,500,10,#PB_ScrollArea_Flat)
CanvasGadget(6,0,0,250,500,#PB_Canvas_Container)
CloseGadgetList()
StartDrawing(CanvasOutput(6))
Box(0,0,250,500,$BBF0FE)
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent )
DrawText(2,2,"ComboBox Item " + Str(1),$FE2D30)
DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
StopDrawing()
HideGadget(5,1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Run ! 1
If Run = 1
HideGadget(5,0)
Else
HideGadget(5,1)
EndIf
Case 6
Select EventType()
Case #PB_EventType_MouseMove
my = GetGadgetAttribute(6, #PB_Canvas_MouseY)
If my > 24 And my < 44 And over = 0
StartDrawing(CanvasOutput(6))
Box(0,24,250,30,$BBF0FE)
DrawingMode(#PB_2DDrawing_Transparent )
DrawingFont(FontID(0))
DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
DrawingMode(#PB_2DDrawing_AlphaBlend )
Box(0,24,250,30,$60FF0000)
StopDrawing()
Else
StartDrawing(CanvasOutput(6))
Box(0,24,250,30,$BBF0FE)
DrawingMode(#PB_2DDrawing_Transparent )
DrawingFont(FontID(0))
DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
StopDrawing()
EndIf
;You can know exactly the what item under the cursor even with the scroll bar moved
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf
Edit : Step forward
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 9:54 pm
by IdeasVacuum
Hi Rashad
That's interesting code but if using a ScrollAreaGadget works, there is no need to use a Canvas, it can host a ListIcon. The reason I use a Window is that you can guarantee it will always be topmost Z level (StickyWindow), whereas I have found using a Container sometimes works, sometimes doesn't when it has to be on top of other gadgets -so to guarantee it is always on top the other gadgets need to be temporarily hidden. If the solution is for just one hand-made combo, either method is good, but for several combos on several tabs, the Window drop-down has an advantage in that it can be recycled.
Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 10:18 pm
by RASHAD
I still advice using the CanvasGadget() more than any other Gadget()
It will be more code to use
But
- You can use more than one font per list
- You can justify the text left-center-right
- you can design the height of any row as you like
- And more and more without any Windows API
Just tuck up your sleeve and dive in

Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 10:22 pm
by davido
@
RASHAD,
Very nice example, as usual.
I'll have to take a close look at it.
Thank you for sharing.

Re: ComboBox Drop-down Height
Posted: Fri Jul 14, 2017 10:28 pm
by RASHAD
Hi davido
You just trapped in mate
You have to roll up your sleeve and finish the exam.
Previous post updated