Function to Tell an image is which?
Im trying to make my life for simple by making a function that returns which image it is.
[CODE] Private Sub WordWrapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordWrapToolStripMenuItem.Click
WordWrapToolStripMenuItem.Image = My.Resources.accept 'check mark (OK)
End Sub
Private Function GetCurrentImage(ByVal FromWhere As System.Windows.Forms.ToolStrip)
If FromWhere = My.Resources.accept Then
MyImage = My.Resource.accept
E
Re: Function to Tell an image is which?
First up, if you've declare the FromWhere parameter as type TooStrip then you can't call the method and pass an Image. If you want to pass an Image to the method then you need to declare the parameter as type Image.
I'm not really sure what that code's for anyway. Why can't you just get the Image from the menu item's Image property? That IS the Image, so why go any further?
Re: Function to Tell an image is which?
Ok I fixed up my code.
Code:
Private Sub WordWrapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordWrapToolStripMenuItem.Click
If GetCurrentImage(WordWrapToolStripMenuItem.Image) = "OK" Then
MsgBox("OK")
End If
End Sub
Private Function GetCurrentImage(ByVal FromWhere As Image)
Dim MyImage As String = Nothing
If FromWhere Is My.Resources.accept Then
MyImage = "OK"
Else
MyImage = "NO"
End If
Return MyImage
End Function
Im getting no return o.o
Re: Function to Tell an image is which?
Your problem now is the fact that accessing My.Resources creates a new object each time. This code:
vb.net Code:
If My.Resources.MyImage Is My.Resources.MyImage Then
MessageBox.Show("Same")
Else
MessageBox.Show("Different")
End If
will display "Different", because two separate Image objects area created and compared. They may look the same, but one is not the other.
What you need to do is access My.Resources once and once only. Declare a member variable of type Image, access My.Resources and assign the result to that variable. Now use that variable everywhere in your code so that you are using the one Image object everywhere.