EDN Admin
Well-known member
Hi
I have 18 small image objects in My.Resources. They are named with an index - as Color00, Color01, Color02 . . . . I was hoping to be able to programmatically refer to them like you could if they were in a filesystem. See how I have had to use a long Select
Case method. Surely there is a better way.
Thanks
<pre class="prettyprint lang-vb Public Class Form3
Private Sub Form3_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Width = 180 : Me.Height = 150
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
ComboBox1.Width = 112 : ComboBox1.ItemHeight = 20
ComboBox1.Left = 30 : ComboBox1.Top = 30
For I As Integer = 0 To 17
ComboBox1.Items.Add(I)
Next
ComboBox1.MaxDropDownItems = 18
ComboBox1.SelectedIndex = 2
End Sub
Private Sub ComboBox1_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Select Case e.Index
Case 0
e.Graphics.DrawImage(My.Resources.Color00, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 1
e.Graphics.DrawImage(My.Resources.Color01, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 2
e.Graphics.DrawImage(My.Resources.Color02, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 3
e.Graphics.DrawImage(My.Resources.Color03, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 4
e.Graphics.DrawImage(My.Resources.Color04, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 5
e.Graphics.DrawImage(My.Resources.Color05, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 6
e.Graphics.DrawImage(My.Resources.Color06, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 7
e.Graphics.DrawImage(My.Resources.Color07, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 8
e.Graphics.DrawImage(My.Resources.Color08, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 9
e.Graphics.DrawImage(My.Resources.Color09, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 10
e.Graphics.DrawImage(My.Resources.Color10, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 11
e.Graphics.DrawImage(My.Resources.Color11, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 12
e.Graphics.DrawImage(My.Resources.Color12, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 13
e.Graphics.DrawImage(My.Resources.Color13, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 14
e.Graphics.DrawImage(My.Resources.Color14, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 15
e.Graphics.DrawImage(My.Resources.Color15, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 16
e.Graphics.DrawImage(My.Resources.Color16, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 17
e.Graphics.DrawImage(My.Resources.Color17, e.Bounds.Left + 1, e.Bounds.Top + 1)
End Select
End Sub
End Class[/code]
<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/223595
<
Leon C Stanley - - A dinky di VBer - -
View the full article
I have 18 small image objects in My.Resources. They are named with an index - as Color00, Color01, Color02 . . . . I was hoping to be able to programmatically refer to them like you could if they were in a filesystem. See how I have had to use a long Select
Case method. Surely there is a better way.
Thanks
<pre class="prettyprint lang-vb Public Class Form3
Private Sub Form3_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Width = 180 : Me.Height = 150
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
ComboBox1.Width = 112 : ComboBox1.ItemHeight = 20
ComboBox1.Left = 30 : ComboBox1.Top = 30
For I As Integer = 0 To 17
ComboBox1.Items.Add(I)
Next
ComboBox1.MaxDropDownItems = 18
ComboBox1.SelectedIndex = 2
End Sub
Private Sub ComboBox1_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Select Case e.Index
Case 0
e.Graphics.DrawImage(My.Resources.Color00, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 1
e.Graphics.DrawImage(My.Resources.Color01, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 2
e.Graphics.DrawImage(My.Resources.Color02, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 3
e.Graphics.DrawImage(My.Resources.Color03, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 4
e.Graphics.DrawImage(My.Resources.Color04, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 5
e.Graphics.DrawImage(My.Resources.Color05, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 6
e.Graphics.DrawImage(My.Resources.Color06, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 7
e.Graphics.DrawImage(My.Resources.Color07, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 8
e.Graphics.DrawImage(My.Resources.Color08, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 9
e.Graphics.DrawImage(My.Resources.Color09, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 10
e.Graphics.DrawImage(My.Resources.Color10, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 11
e.Graphics.DrawImage(My.Resources.Color11, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 12
e.Graphics.DrawImage(My.Resources.Color12, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 13
e.Graphics.DrawImage(My.Resources.Color13, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 14
e.Graphics.DrawImage(My.Resources.Color14, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 15
e.Graphics.DrawImage(My.Resources.Color15, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 16
e.Graphics.DrawImage(My.Resources.Color16, e.Bounds.Left + 1, e.Bounds.Top + 1)
Case 17
e.Graphics.DrawImage(My.Resources.Color17, e.Bounds.Left + 1, e.Bounds.Top + 1)
End Select
End Sub
End Class[/code]
<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/223595
<
Leon C Stanley - - A dinky di VBer - -
View the full article