Hi,
Set the listbox draw mode to ownerdrawnfixed to control how the
text is aligned. This example will use a stringformat to center the text
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
For x As Integer = 0 To 20
ListBox1.Items. Add(x)
Next
End Sub
Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim g As Graphics = e.Graphics
Dim br As SolidBrush
Dim s As String
Dim sf As New StringFormat
sf.Alignment = StringAlignment .Center
Try
s = ListBox1.Items. Item(e.Index).T oString
Catch ex As Exception
s = ""
Trace.WriteLine (ex.ToString)
End Try
br = New SolidBrush(Colo r.White)
g.FillRectangle (br, e.Bounds)
If CBool(e.State And DrawItemState.S elected) Then
g.FillRectangle (Brushes.LightB lue, e.Bounds)
End If
g.DrawString(s, ListBox1.Font, Brushes.Black, _
RectangleF.op_I mplicit(e.Bound s), sf)
br.Dispose()
End Sub
End Class
Ken
-------------------
"Tom McL." <tb***@cwnet.co m> wrote in message
news:ue******** ******@tk2msftn gp13.phx.gbl...
I would like to align text in a ListBox to achieve columns.
In the past I could determine the text width in Twips and
pad in required number of blank spaces. But now I'm using
VB2005 and it does not support Twips. How do I accomplish this?
Thanks