Bonsoir
Y a t-il un moyen de centrer le texte affiché dans une comboBoxGadget?
Merci
Centrer le text dans une ComboBoxGadget
Centrer le text dans une ComboBoxGadget
Win7 (x64)
Pb 6.03 LTS
Pb 6.03 LTS
Re: Centrer le text dans une ComboBoxGadget
Si le gadget n'est jamais redimensionné:
sinon
M.
Code : Tout sélectionner
Procedure _GetGadgetText(gad)
text$ = LTrim(GetGadgetText(gad)," ")
Debug text$
EndProcedure
Procedure _AddGadgetItem(gad,Text$)
gadw = GadgetWidth(gad,#PB_Gadget_ActualSize); - GadgetWidth(gad,#PB_Gadget_RequiredSize)
StartDrawing(WindowOutput(0))
DrawingFont(FontID(0))
width = TextWidth(Text$)
width2 = TextWidth(" ")
StopDrawing()
trim = (gadw - width)/2/width2
text$ = Space(trim)+text$
AddGadgetItem(gad, -1,text$)
EndProcedure
LoadFont(0,"Tahoma",14)
If OpenWindow(0, 0, 0, 400, 400, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 20)
SetGadgetFont(0,FontID(0))
StartDrawing(WindowOutput(0))
DrawingFont(FontID(0))
height = TextHeight("Q")+10
StopDrawing()
ResizeGadget(0,#PB_Ignore,#PB_Ignore,#PB_Ignore,height)
_AddGadgetItem(0,"IdeasVacuum")
_AddGadgetItem(0,"ComboBox item #!")
_AddGadgetItem(0,"RASHAD")
SetGadgetState(0,1)
ButtonGadget(1,10,370,80,25,"Get Text")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
_GetGadgetText(0)
EndSelect
EndSelect
Until Quit = 1
EndIf
Code : Tout sélectionner
EnableExplicit
Procedure WindowCallback(WindowHandle.I, Message.I, WParam.I, LParam.I)
Protected Brush.I
Protected DC.I
Protected *DrawItem.DRAWITEMSTRUCT
Protected ItemText.S
Protected Result.I
Protected Size.SIZE
Protected x.I
Result = #PB_ProcessPureBasicEvents
If Message = #WM_DRAWITEM
*DrawItem = LParam
If *DrawItem\CtlType = #ODT_COMBOBOX
SetBkMode_(*DrawItem\hDC, #TRANSPARENT)
If *DrawItem\ItemState & #ODS_FOCUS
Brush = CreateSolidBrush_($FF901E)
FillRect_(*DrawItem\hDC, *DrawItem\rcItem, Brush)
DeleteObject_(Brush)
SetTextColor_(*DrawItem\hDC, $FFFFFF)
Else
FillRect_(*DrawItem\hDC, *DrawItem\rcItem,
GetStockObject_(#WHITE_BRUSH))
EndIf
If *DrawItem\itemID <> -1
ItemText = Space(128)
SendMessage_(*DrawItem\hwndItem, #CB_GETLBTEXT,
*DrawItem\itemID, @ItemText)
DC = GetDC_(WindowHandle)
SelectObject_(DC, GadgetID(WParam))
GetTextExtentPoint32_(DC, @ItemText, Len(ItemText), Size)
ReleaseDC_(GadgetID(WParam), DC)
x = *DrawItem\rcItem\left +
(*DrawItem\rcItem\right - *DrawItem\rcItem\left - Size\cx) / 2
TextOut_(*DrawItem\hDC, x, *DrawItem\rcItem\top, ItemText,
Len(ItemText))
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Define i.I
OpenWindow(0, 200, 100, 270, 130, "ComboBoxGadget demo")
SetGadgetFont(#PB_Default, LoadFont(0, "Verdana", 10))
ComboBoxGadget(0, 10, 20, 120, 23)
ComboBoxGadget(1, 140, 20, 120, 23, #CBS_OWNERDRAWFIXED | #CBS_HASSTRINGS)
SetWindowCallback(@WindowCallback())
For i = 1 To 5
AddGadgetItem(0, -1, "Item " + Str(i))
AddGadgetItem(1, -1, "Item " + Str(i))
Next
SetGadgetState(0, 0)
SetGadgetState(1, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow