I'm attempting to make some custom classes (comboboxes) for setting MSChart attributes and I'm stuck on line weights. I had done experiments in a sub where I'd create a bitmap/imagelist of different line weights and add that to the combobox. Once that was working I started on a custom class to do the line weights. I'm almost there but I seem to be doing all the drawing on the first item's graphic area while the rest are empty. I can't seem to figure out how to specify each item's graphic instead of just the first one. Can anyone spot the problem?
Here's the class code
Here's the class code
VB.NET:
Public Class LineWeightComboBox
Inherits ComboBox
Public Property LineWeight As Integer
Public Property MinWeight As Integer = 1
Public Property MaxWeight As Integer = 3
Public Sub New()
Dim intCount As Integer
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
Me.DropDownStyle = ComboBoxStyle.DropDownList
For intCount = 1 To 3
MyBase.Items.Add(intCount)
Next
End Sub
Private Sub LineWeightComboBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
Dim pPen As Pen
Dim gr As Graphics = e.Graphics
Dim fFont As Font = Me.Font
Dim w As Integer = e.Bounds.Bottom - e.Bounds.Top
If e.Index >= 0 Then
pPen = New Pen(Color.Black, e.Index)
Debug.Print("e.index" & e.Index)
gr.Clear(e.BackColor)
gr.DrawLine(pPen, e.Bounds.Left, CInt(e.Bounds.Height / 2), e.Bounds.Width, CInt(e.Bounds.Height / 2))
End If
End Sub
End Class