Re: Combobox and Text value
You can use a hashtable
Code:
Public Class Form1
Dim az As Hashtable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
az = New Hashtable()
az.Add("chat", "C:\LeaveSheet.JPG")
az.Add("chien", "C:\untitled.bmp")
ComboBox1.Items.Add("dog")
ComboBox1.Items.Add("cat")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
PictureBox1.Image = Image.FromFile(az(ComboBox1.SelectedItem.ToString).ToString)
Catch ex As Exception
' Handle exception
End Try
End Sub
End Class
Re: Combobox and Text value
Thank you for that useful reply. One more thing, how could you do that when the mouse passes over a name, photo change by itself? unless I have to click ..
I hesitate a mousesomething ..
Re: Combobox and Text value
Example: The mouse is over ListBox2, we have eX and eY as screen coordinates, and now how to get the index.
We will first turn eX and eY in client coordinates (relative to the listbox)
ListBox2.PointToClient(New Point(e.X, e.Y)
Then ListBox2.IndexFromPoint () will return the index overflown.
Private Sub ListBox2_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
_Handles ListBox2.DragOver
IndexdInsertion = ListBox2.IndexFromPoint(ListBox2.PointToClient(New Point(e.X, e.Y)))
End Sub
Re: Combobox and Text value
I tried, I said that is not declared IndexedInsertion and ComboRace.IndexFromPoint for the IndexFromPoint is not a member of System.Windows.Form.ComboBox
I have to have 5 different controls, and I want to use a combobox so is this possible with what I want to do?
Re: Combobox and Text value
For the combobox, I think it is possible because the listbox is admitted of the two dimension x, y. You can test including your picture in combobox. If you're interested in, here is an example
In the load or when filling your combobox
Code:
Dim items(Me.ImageList1.Images.Count - 1) As String
For i As Int32 = 0 To Me.ImageList1.Images.Count - 1
items(i) = "Item " & i.ToString
Next
Me.ComboBox1.Items.AddRange(items)
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height
Me.ComboBox1.Width = Me.ImageList1.ImageSize.Width + 18
Me.ComboBox1.MaxDropDownItems = Me.ImageList1.Images.Count
In the event of combobox1_draw
Code:
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index <> -1 Then
If e.Index <> -1 Then
e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top)
End If
End If
End Sub
In the event ComboBox1_MeasureItem
Code:
Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem
e.ItemHeight = Me.ImageList1.ImageSize.Height
e.ItemWidth = Me.ImageList1.ImageSize.Width
End Sub