i'm sorry, i can barely grasp what you meant about the .tostring() part. i'm
not yet familiar on this language. can you elaborate more... tnx...
> i'm sorry, i can barely grasp what you meant about the .tostring() part.
> i'm
> not yet familiar on this language. can you elaborate more... tnx...
Example of a custom class overriding the .tostring function
(overriding isnt something you will probably need, but...)
(if you get confused... dont worry - it doesnt look like you needed custom
classes anyway)
Description:
Button1 puts the custom object into the combobox (and uses its .tostrong
override), Button2 copies the selected-object from the combobox to the
picturebox... this could be any of the objects in its list, although the
example only shows adding one object derived from the custom class. The
objects in the combobox could be a mixture of different custom objects,
strings, images, other comboboxes, etc.
Controls needed on form:
*ComboBox1
* Button1
* Button2
* Picturebox1
Code:
Public Class Form1
Private myImg As New cMyImg("C:\smiley.jpg")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ComboBox1.Items.Add(myImg)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
PictureBox1.Image = ComboBox1.SelectedItem
End Sub
End Class
Public Class cMyImg
Public Img As Bitmap
Private ImagePath As String = ""
'Here is an overriding function
Overrides Function ToString() As String
If ImagePath = "" Then
ToString = "{NoImageSet}"
Else
ToString = "{" & ImagePath & ")"
End If
End Function
Public Sub SetImage(ByVal filepath As String)
Try
Img = New Bitmap(filepath)
ImagePath = filepath
Catch
End Try
End Sub
Public Sub New(ByVal filepath As String)
Try
Img = New Bitmap(filepath)
ImagePath = filepath
Catch
End Try
End Sub
End Class