Belini

Center text in ComboBox

5 posts in this topic

#1 ·  Posted

I wanted to show the centralized events in the combobox, is there a way to centralize the text?

Share this post


Link to post
Share on other sites



#2 ·  Posted

On searching forum what i could find is this

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here is a method to center text in a combo control.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
; Ref: https://www.autoitscript.com/forum/topic/119009-combo-and-format-issue-aligning-text/?do=findComment&comment=827534

Local $data[20]
Local $iComboWidth = 249

Local $gui = GUICreate('', 260, 410)
Local $test = GUICtrlCreateCombo('', 0, 0, $iComboWidth, 400, $WS_VSCROLL)
GUICtrlSetFont(-1, 10, Default, Default, "Consolas") ; <<<<<<<<<<<<<<<< From above https reference thread.
GUISetState()

; ---- Generate data ---------
For $i = 0 To UBound($data) - 1
    For $j = 0 To Random(2, 10)
        $data[$i] &= Random(1, 10, 1)
    Next
Next
; ---- End of Generate data ---------

_CentreData($iComboWidth, $data)

; Set data to the control.
For $i = 0 To UBound($data) - 1
    GUICtrlSetData($test, $data[$i])
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        MsgBox(0, "", "Selected: " & StringStripWS(GUICtrlRead($test), 3), 4) ; $STR_STRIPLEADING (1) = strip leading white space plus $STR_STRIPTRAILING (2) = strip trailing white space
        ExitLoop
    EndIf
WEnd


; Centre each item in the $aData array, relative to the $iComboWidth.
Func _CentreData($iComboWidth, ByRef $aData)
    Local $strintest = Int(($iComboWidth / 8.3) / 2) ; Find centre of combo window width 8.3 pixels per character

    ; Add spaces to each item to Centre text.
    For $i = 0 To UBound($aData) - 1
        While Int(StringLen($aData[$i]) / 2) < $strintest
            $aData[$i] = ' ' & $aData[$i] & ' '
        WEnd
    Next
EndFunc   ;==>_CentreData

 

Edited by Malkey
The If expression and the Until expression were replaced by the one While expression in the _CentreData() function..
1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now