Page 1 of 1

Item Height in a ComboBoxGadget

Posted: Thu Feb 22, 2024 2:32 pm
by blueb
Quick question... concerning the list of items inside a ComboBoxGadget().

I can make the ComboBox height any size I need, but I couldn't find a way to alter the default height of the items inside the list. (it's for a touch tablet, and the default is way too small for fingers. haha).

Any pointers?
It's for Windows machine but cross platform would be better.

Re: Item Height in a ComboBoxGadget

Posted: Thu Feb 22, 2024 3:09 pm
by Shardik

Code: Select all

EnableExplicit

Define i.I
Define ItemHeight.I

OpenWindow(0, 0, 0, 390, 180, "",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 180, 21)
ComboBoxGadget(1, 200, 10, 180, 21)

For i = 1 To 5
  AddGadgetItem(0, -1,"ComboBox item " + Str(i))
  AddGadgetItem(1, -1,"ComboBox item " + Str(i))
Next

SetGadgetState(0, 0)
SetGadgetState(1, 0)

; ----- Get default item height in 1st ComboBox
ItemHeight = SendMessage_(GadgetID(0), #CB_GETITEMHEIGHT, -1 ,0)
SendMessage_(GadgetID(0), #CB_SETITEMHEIGHT, 0, ItemHeight)

; ----- Add 15 to item height in 2nd ComboBox
SendMessage_(GadgetID(1), #CB_SETITEMHEIGHT, 0, ItemHeight + 15)

; ----- Open 2nd ComboBox to show increased item height
SendMessage_(GadgetID(1), #CB_SHOWDROPDOWN, 1, 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Item Height in a ComboBoxGadget

Posted: Thu Feb 22, 2024 3:11 pm
by RASHAD
For Windows

Code: Select all

Global Text$,Brush,Brush_2

Text$ = Space(#MAX_PATH)

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

LoadFont(0,"Tahoma",12,#PB_Font_Bold)

If OpenWindow(0, 0, 0, 280, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WndProc())
  ComboBoxGadget(0 ,10, 10, 260, 40,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS)
  SetGadgetFont(0,FontID(0))
  SendMessage_(GadgetID(0), #CB_SETITEMHEIGHT, 0, 40)
  
  For a = 0 To 10
    AddGadgetItem(0, -1,"ComboBox Item " + Str(a))
  Next
  
  SetGadgetState(0, 2)     
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Re: Item Height in a ComboBoxGadget

Posted: Thu Feb 22, 2024 8:25 pm
by blueb
Thanks Shardik and Rashad.

I thought I'd have to dip into the Windows API... but they work great.

I've added both to my arsenal... funny the topic hasn't come up more often, especially with higher resolution screens (I have a 4k monitor).

Thanks again, very useful stuff.