Results 1 to 10 of 10

Thread: [RESOLVED] Picture Box Glitch

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    230

    Resolved [RESOLVED] Picture Box Glitch

    Hello and thanks for taking a look at this.

    To make this simple i have a multiple forms. On form 1 is a picturebox whose image property is set through a series of case statements as follows:

    Code:
     If (MyImage IsNot Nothing) Then
                MyImage.Dispose()
            End If
    
            Select Case cnt_ACerv
    
    
                'Case 1
                '    MyImage = My.Resources.cervAP17
                'Case 2
                '    MyImage = My.Resources.cervAP18
                'Case 3
                '    MyImage = My.Resources.cervAP19
                'Case 4
                '    MyImage = My.Resources.cervAP20
                Case 6
                    MyImage = My.Resources.cervAP22
                Case 7
                    MyImage = My.Resources.cervAP23
                Case 8
                    MyImage = My.Resources.cervAP24
                Case 9
                    MyImage = My.Resources.cervAP25
                Case 11
                    MyImage = My.Resources.cervAP27
                Case 12
                    MyImage = My.Resources.cervAP28
                Case 13
                    MyImage = My.Resources.cervAP29
                Case 14
                    MyImage = My.Resources.cervAP30
                Case 16
                    MyImage = My.Resources.cervAP32
                Case 17
                    MyImage = My.Resources.cervAP33
                Case 18
                    MyImage = My.Resources.cervAP34
                Case 19
                    MyImage = My.Resources.cervAP35
                Case 21
                    MyImage = My.Resources.cervAP37
                Case 22
                    MyImage = My.Resources.cervAP38
                Case 23
                    MyImage = My.Resources.cervAP39
                Case 24
                    MyImage = My.Resources.cervAP40
                Case 26
                    MyImage = My.Resources.cervAP42
                Case 27
                    MyImage = My.Resources.cervAP43
                Case 28
                    MyImage = My.Resources.cervAP44
                Case 29
                    MyImage = My.Resources.cervAP45
    
            End Select
            If cnt_ACerv > 30 Then
                If cnt_ACerv < 37 Then
                    MyImage = My.Resources.cervAP45
                End If
            End If
            If cnt_ACerv < 37 Then
                guide.Image = CType(MyImage, Image)
            End If
    
            Return 0
    The issue is that whenever i navigate away from this form and then back to it the picturebox is glitched and will only appear as a white box with a red X through it.

    Im sure there is something simple i am missing or a refresh that needs to be done but at this point i am unaware of what to look for. I have checked the variables inside my case statements before i navigate away and after i navigate back and they appear to be correct at both points.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Picture Box Glitch

    It's going to probably be because of the Dispose call. If you remove it, then does it work as expected? How and where are you calling this code?

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Picture Box Glitch

    A couple suggestions, though:

    The Select Case statement is pretty versatile - you can eliminate your second-to-last If block and Case statement and simply add:

    Code:
    Case 29 To 36
        MyImage = My.Resources.cervAP45
    You could also use a With block to avoid the variable and extra If statement, too:

    Code:
            With guide
            Select Case cnt_ACerv
                'Case 1
                '    .Image = My.Resources.cervAP17
                'Case 2
                '    .Image = My.Resources.cervAP18
                'Case 3
                '    .Image = My.Resources.cervAP19
                'Case 4
                '    .Image = My.Resources.cervAP20
                Case 6
                    .Image = My.Resources.cervAP22
                Case 7
                    .Image = My.Resources.cervAP23
                Case 8
                    .Image = My.Resources.cervAP24
                Case 9
                    .Image = My.Resources.cervAP25
                Case 11
                    .Image = My.Resources.cervAP27
                Case 12
                    .Image = My.Resources.cervAP28
                Case 13
                    .Image = My.Resources.cervAP29
                Case 14
                    .Image = My.Resources.cervAP30
                Case 16
                    .Image = My.Resources.cervAP32
                Case 17
                    .Image = My.Resources.cervAP33
                Case 18
                    .Image = My.Resources.cervAP34
                Case 19
                    .Image = My.Resources.cervAP35
                Case 21
                    .Image = My.Resources.cervAP37
                Case 22
                    .Image = My.Resources.cervAP38
                Case 23
                    .Image = My.Resources.cervAP39
                Case 24
                    .Image = My.Resources.cervAP40
                Case 26
                    .Image = My.Resources.cervAP42
                Case 27
                    .Image = My.Resources.cervAP43
                Case 28
                    .Image = My.Resources.cervAP44
                Case 29 To 36
                    .Image = My.Resources.cervAP45
            End Select
            End With
    or even:

    Code:
    'Untested but should work
    If cnt_ACerv < 29 Then
        guide.Image = DirectCast(My.Resources.ResourceManager.GetObject("cervAP" & (cnt_ACerv + 16).ToString()), Image)
    ElseIf cnt_ACerv < 37 Then
        guide.Image = My.Resources.cervAP45
    End If
    You also probably don't need the .Dispose() and as ForumAccount pointed out, it's probably the cause of your problem.
    Last edited by minitech; Jun 20th, 2011 at 06:32 PM.

  4. #4
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: Picture Box Glitch

    save the images you will use in an array or variables :

    Code:
    Dim fs As IO.FileStream = New IO.FileStream(TextBox2.Text, IO.FileMode.Open)
            Dim image1 As Image = Image.FromStream(fs) ' or as bitmap
            fs.Close()
    then : MyImage = image1

    instead of dispose set the picture box visible property to false or nothing or a grey image

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Picture Box Glitch

    No, @moti barksi, that's the wrong way to go about things and definitely does not solve the problem.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    230

    Re: Picture Box Glitch

    Simply removing the Dispose line worked fine for me .

  7. #7
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: Picture Box Glitch

    Quote Originally Posted by minitech View Post
    No, @moti barksi, that's the wrong way to go about things and definitely does not solve the problem.


    so I got the correct answer according to post #6 and you(minitech) reward me by reddening my rate bar, how do you think that make me feel ?

    point for deos ex machina
    Last edited by moti barski; Jun 20th, 2011 at 07:02 PM.

  8. #8

    Re: Picture Box Glitch

    Quote Originally Posted by moti barski View Post


    so I got the correct answer according to post #6 and you(minitech) reward me by reddening my rate bar, how do you think that make me feel ?

    point for deos ex machina
    No, you did not get the correct answer. The OP said removing the Dispose() line worked, which is what a few people have already said from earlier (ForumAccount and Minitech).

  9. #9
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: Picture Box Glitch

    whatevea, just try not to take your frustrations out on me minitech.

  10. #10
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Picture Box Glitch

    No, not "whatever"; formlesstree4's answer is the answer to your question. I assure you I'm not taking frustration out on you.

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