Hi!
In VB.NET want to draw my own items in a ComboBox
I have added a ComboBox to the Form with this.
-----------------------------------------------------------------------------------
'ComboBox1
'
Me.ComboBox1.Dr awMode = System.Windows. Forms.DrawMode. OwnerDrawFixed
Me.ComboBox1.Lo cation = New System.Drawing. Point(16, 232)
Me.ComboBox1.Na me = "ComboBox1"
Me.ComboBox1.Si ze = New System.Drawing. Size(121, 21)
Me.ComboBox1.Ta bIndex = 13
Me.ComboBox1.Te xt = "ComboBox1"
AddHandler Me.ComboBox1.Dr awItem, AddressOf ComboBox1_DrawI tem
---------------------------------
Private Sub FSMmain_Load(By Val sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
ComboBox1.Items .Add("Item1")
ComboBox1.Items .Add("Item2")
ComboBox1.Items .Add("Item3")
End Sub
-------------------------------
'And then the Draw item Sub
Private Sub ComboBox1_DrawI tem(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs)
Dim g As Graphics = e.Graphics
Dim r As Rectangle = e.Bounds
Dim fn As New Font("Verdana", 8, FontStyle.Regul ar)
If e.Index >= 0 Then
Dim s As String = sender.Items(e. Index)
Dim sf As New StringFormat
sf.Alignment = StringAlignment .Near
Console.WriteLi ne(e.State.ToSt ring())
e.Graphics.Draw Rectangle(New Pen(New SolidBrush(Colo r.Black), 2), r)
If e.State = DrawItemState.N oAccelerator Or e.State = DrawItemState.N oFocusRect Then
e.Graphics.Fill Rectangle(New SolidBrush(Colo r.White), r)
e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.Black), r.X, r.Y)
e.DrawFocusRect angle()
Else
e.Graphics.Fill Rectangle(New SolidBrush(Colo r.LightBlue), r)
e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.White), r.X, r.Y)
e.DrawFocusRect angle()
End If
End If
End Sub
----------------------------------------------------------
My Problem is this, When I Click the ComboBox it drops down with a white aream big enough for the 3 items but it's empty and then after 2 seconds the Items show with LightBlue Background and Black text and then when I move away from it the Black border of the Combobox staty painted. There's no crash or anything, just feels like it's really "well".
Any ideas what might be wrong?
I have Based this on the C# examples found here. http://www.csharphelp.com/archives2/archive316.html
The Examples works fine for me.. but I want to translate this into VB and I can't figure out what I'm missing.. or is there a Differance in the C# and VB languages for this kind of work?
Best Regards
/Lars Netzel