Dave der Code vom Manfrad klappt ja auch..nur meiner nicht...
ich fülle die Listbox so:
.cblland.Items.Clear()
.cblland.Items.AddRange(database.OptionList("Land").ToArray) Desweiteren habe ich dann nur noch ein Pint Event mir gebastelt das so aussieht ( bin grade dabei mir dafür auch ein CustomControl zu erstellen, da ich diese Art Listbox öfter benötige)
Private Sub cblland_DrawItem(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DrawItemEventArgs) Handles cblland.DrawItem
e.DrawBackground()
Dim drawFont As Font = e.Font
Dim lCategory As Boolean = False
Dim lCheckBoxWidth As Integer = 15
Dim IImageBoxWidth As Integer = e.Bounds.Height * 2
If lCategory Then lCheckBoxWidth = 0
Dim lStringRectf As New RectangleF(e.Bounds.X + lCheckBoxWidth + _
IImageBoxWidth + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
Dim lCheckBoxRect As New Rectangle(e.Bounds.X + 5, e.Bounds.Y, _
lCheckBoxWidth, e.Bounds.Height)
Dim lItemSelected As Boolean = ((e.State And DrawItemState.Selected) = _
DrawItemState.Selected)
If lItemSelected And Not lCategory Then
Dim myBrush As Brush = New System.Drawing.SolidBrush(e.ForeColor)
e.Graphics.FillRectangle(myBrush, e.Bounds)
ControlPaint.DrawCheckBox(e.Graphics, lCheckBoxRect, _
ButtonState.Checked)
If File.Exists(DBOption.TextBox13.Text & sender.Items( _
e.Index).ToString() & ".png") Then
Dim oStream As New System.IO.FileStream(DBOption.TextBox13.Text _
& sender.Items(e.Index).ToString() & ".png", IO.FileMode.Open)
e.Graphics.DrawImage(New Bitmap(oStream), e.Bounds.X + _
lCheckBoxWidth + 10, e.Bounds.Y, IImageBoxWidth, _
e.Bounds.Height)
oStream.Close()
End If
e.Graphics.DrawString(e.Index & " " & sender.Items( _
e.Index).ToString(), drawFont, New SolidBrush(colors), _
lStringRectf)
ElseIf lItemSelected And lCategory Then
Dim myBrush As Brush = New System.Drawing.SolidBrush(e.ForeColor)
e.Graphics.FillRectangle(myBrush, e.Bounds)
ControlPaint.DrawCheckBox(e.Graphics, lCheckBoxRect, _
ButtonState.Normal)
If File.Exists(DBOption.TextBox13.Text & sender.Items( _
e.Index).ToString() & ".png") Then
Dim oStream As New System.IO.FileStream(DBOption.TextBox13.Text _
& sender.Items(e.Index).ToString() & ".png", IO.FileMode.Open)
e.Graphics.DrawImage(New Bitmap(oStream), e.Bounds.X + _
lCheckBoxWidth + 10, e.Bounds.Y, IImageBoxWidth, _
e.Bounds.Height)
oStream.Close()
End If
e.Graphics.DrawString(sender.Items(e.Index).ToString(), drawFont, _
New SolidBrush(colors), lStringRectf)
Else
ControlPaint.DrawCheckBox(e.Graphics, lCheckBoxRect, _
ButtonState.Normal)
If File.Exists(DBOption.TextBox13.Text & sender.Items( _
e.Index).ToString() & ".png") Then
Dim oStream As New System.IO.FileStream(DBOption.TextBox13.Text _
& sender.Items(e.Index).ToString() & ".png", IO.FileMode.Open)
e.Graphics.DrawImage(New Bitmap(oStream), e.Bounds.X + _
lCheckBoxWidth + 10, e.Bounds.Y, IImageBoxWidth, _
e.Bounds.Height)
oStream.Close()
End If
e.Graphics.DrawString(sender.Items(e.Index).ToString(), drawFont, _
New SolidBrush(colors), lStringRectf)
End If
e.DrawFocusRectangle()
End Sub Wie schon gesagt, es klappt auch alles prima, bis auf dieses kleine Anzeigenproblem.
Gruss Caddy
Beitrag wurde zuletzt am 31.10.11 um 15:08:18 editiert. |