Solo incluyo alineamiento de items a la derecha e izquierda, porque para centrarlos hay que hacerlo de forma diferente.
Posteado en http://www.visual-coders.com.ar/
Código
Option Explicit '========================================================= ' º Function : AlignListBox ' º Author : Mr. Frog © ' º Mail : vbpsyke1@mixmail.com ' º Recommended Websites : ' http://visual-coders.com.ar ' http://InfrAngeluX.Sytes.Net ' http://twitter.com/#!/PsYkE1 '========================================================= Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Const GWL_EXSTYLE As Long = (-20) Private Const WS_EX_RIGHT As Long = &H1000& Private Const WS_EX_LEFT As Long = &H0& Private Const WS_EX_LEFTSCROLLBAR As Long = &H4000& Private Const WS_EX_RIGHTSCROLLBAR As Long = &H0& Public Enum AlignConstants aLeft = 0 aRight = 1 End Enum Public Enum OptionAlign Items = 0 ScollBar = 1 End Enum Public Function AlignListBox(ByVal myListBox As ListBox, _ ByVal ThingToAlign As OptionAlign, _ Optional ByVal Align As AlignConstants = aLeft) As Long Dim lStyle As Long Dim lHwnd As Long If Not (myListBox Is Nothing) Then lHwnd = myListBox.hwnd lStyle = GetWindowLong(lHwnd, GWL_EXSTYLE) If Align = aRight Then If ThingToAlign = Items Then lStyle = lStyle Or WS_EX_RIGHT Else lStyle = lStyle And WS_EX_RIGHTSCROLLBAR End If Else If ThingToAlign = Items Then lStyle = lStyle And WS_EX_LEFT Else lStyle = lStyle Or WS_EX_LEFTSCROLLBAR End If End If AlignListBox = SetWindowLong(lHwnd, GWL_EXSTYLE, lStyle) End If End Function
Ejemplo:
Código
Option Explicit Private Sub Form_Load() Dim Q As Long For Q = 0 To (Screen.FontCount - 1) List1.AddItem Screen.Fonts(Q) Next Q AlignListBox List1, Items, aRight 'AlignListBox List1, Items, aLeft AlignListBox List1, ScollBar, aLeft 'AlignListBox List1, ScollBar, aRight End Sub
Resultado:
DoEvents!