Results 1 to 4 of 4

Thread: Function to Tell an image is which?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    193

    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
    Last edited by NoobieO.o; Apr 15th, 2010 at 12:48 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    193

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. If My.Resources.MyImage Is My.Resources.MyImage Then
    2.     MessageBox.Show("Same")
    3. Else
    4.     MessageBox.Show("Different")
    5. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width