Seite 1 von 1

ComboBoxGadget zentriert, rechtsbündig editierbar

Verfasst: 28.11.2017 10:43
von marcelx
Hallo,
ich möchte ComboBoxGadget in alle Varianten haben:
mit/ohne editierbar, linksbündig, zentriert und rechtsbündig.
Mit mein Test-Code funktioniert es nicht.

Code: Alles auswählen

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  ComboBoxGadget(1, 10, 10, WindowWidth(0)-20, 20); |#PB_ComboBox_Editable)
  AddGadgetItem(1, -1,"left")
  SetGadgetState(1, 0)
 
  ComboBoxGadget(2, 10, 30, WindowWidth(0)-20, 20, #PB_Text_Center) ; |#PB_ComboBox_Editable
  AddGadgetItem(2, -1,"center")
  SetGadgetState(2, 0)
  
  ComboBoxGadget(3, 10, 50, WindowWidth(0)-20, 20, #SS_RIGHT) ; |#PB_ComboBox_Editable
  AddGadgetItem(3, -1,"right")
  SetGadgetState(3, 0)  

 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Danke und Gruß
MarcelX

Re: ComboBoxGadget zentriert, rechtsbündig editierbar

Verfasst: 28.11.2017 11:05
von RSBasic
Bitte verwende nicht einfach irgendwelche Konstanten. Eine #SS_-Konstante steht für Static Styles und ComboBoxGadget ist kein Static Control. Dafür gibt es #CBS_-/#CB_-Konstanten.
Außerdem gibt es (wenn #PB_ComboBox_Editable aktiviert ist) im ComboBoxGadget ein StringGadget, welches du mit #ES_/#EM-Konstanten ansteuern kannst.

Hier ein paar Beispielcodes:
#PB_ComboBox_Editable & linksbündig:

Code: Alles auswählen

EnableExplicit

Define hComboEdit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(1, 10, 10, 200, 20, #PB_ComboBox_Editable)
  AddGadgetItem(1, -1, "123")
  SetGadgetState(1, 0)
  
  hComboEdit = FindWindowEx_(GadgetID(1), #Null, "Edit", #Null)
  SetWindowLongPtr_(hComboEdit, #GWL_STYLE, GetWindowLongPtr_(hComboEdit, #GWL_STYLE) | #ES_LEFT)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
#PB_ComboBox_Editable & zentriert:

Code: Alles auswählen

EnableExplicit

Define hComboEdit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(1, 10, 10, 200, 20, #PB_ComboBox_Editable)
  AddGadgetItem(1, -1, "123")
  SetGadgetState(1, 0)
  
  hComboEdit = FindWindowEx_(GadgetID(1), #Null, "Edit", #Null)
  SetWindowLongPtr_(hComboEdit, #GWL_STYLE, GetWindowLongPtr_(hComboEdit, #GWL_STYLE) | #ES_CENTER)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
#PB_ComboBox_Editable & rechtsbündig:

Code: Alles auswählen

EnableExplicit

Define hComboEdit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(1, 10, 10, 200, 20, #PB_ComboBox_Editable)
  AddGadgetItem(1, -1, "123")
  SetGadgetState(1, 0)
  
  hComboEdit = FindWindowEx_(GadgetID(1), #Null, "Edit", #Null)
  SetWindowLongPtr_(hComboEdit, #GWL_STYLE, GetWindowLongPtr_(hComboEdit, #GWL_STYLE) | #ES_RIGHT)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Zenrtiert und rechtsbündig ohne #PB_ComboBox_Editable habe ich gerade keine Beispielcode. Da müsste ich erst auf MSDN schauen, wenn ich Zeit habe, aber wann weiß ich nicht.

Re: ComboBoxGadget zentriert, rechtsbündig editierbar

Verfasst: 28.11.2017 11:40
von marcelx
Danke RSBasic für die 3 Lösungen mit #PB_ComboBox_Editable.
(und es funktioniert)