Retaining index of current image

This question relates to PAQ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22062589.html
 of which I seem to have lost the plot.

The answer that Idle_Mind gave me in that PAQ allows me to displays an array of thumbnail images, loaded from a folder.
My question is; how do I retain the index of the current image so that I can show/remove a border around the currently selected image, but turn off the border of the 'old' image?

Thanks.

tvtechAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Alrighty...try this instead:

Private selectedIndex As Integer

Private Sub Form_Load()
    ' ... previous code remains in Form_Load() ...

    ' add the line below...
    selectedIndex = -1
End Sub

Private Sub picThumb_Click(Index As Integer)
    If selectedIndex <> -1 Then
        DrawBox selectedIndex
    End If
   
    selectedIndex = Index
    DrawBox selectedIndex
End Sub

Private Sub DrawBox(ByVal Index As Integer)
    picThumb(Index).ScaleMode = vbPixels
    picThumb(Index).DrawMode = vbInvert
    picThumb(Index).DrawWidth = 3
   
    ' draw something in the box
    ' (we are using vbInvert so it will be erased when we draw the same thing again)
    picThumb(Index).Line (5, 5)-(picThumb(Index).ScaleWidth - 5, picThumb(Index).ScaleHeight - 5), , B
    picThumb(Index).Line (10, 10)-(picThumb(Index).ScaleWidth - 10, picThumb(Index).ScaleHeight - 10), , B
    picThumb(Index).Circle (picThumb(Index).ScaleWidth / 2, picThumb(Index).ScaleHeight / 2), 10
    picThumb(Index).Circle (picThumb(Index).ScaleWidth / 2, picThumb(Index).ScaleHeight / 2), 15
End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You don't actually need to "remember" anything if you want just ONE image to be selected at a time.

The controls are part of control arrays so just loop thru and turn off everything that isn't the current item.

Something like:

    Private Sub Label1_Click(Index As Integer)
        Dim i As Integer
        For i = Label1.LBound To Label1.UBound
            If i = Index Then
                Label1(i).BackColor = vbBlue ' this is the selected item
            Else
                Label1(i).BackColor = vbWhite ' turn "off" everything else
            End If
        Next i
    End Sub



0
 
tvtechAuthor Commented:
Thanks I_M

  That code will make all non-selected PictureBoxes turn white (Obliterates images) and the current image turns blue. The Labels are not displayed in my code. I basically only need a highlighter around the current image. Where did I go wrong? :-(

Thanks.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tvtechAuthor Commented:
Should have shown the code....

    Dim i As Integer
    For i = lblThumb.LBound To lblThumb.UBound
        If i = Index Then
            picThumb(i).BackColor = vbBlue ' this is the selected item
        Else
            picThumb(i).BackColor = vbWhite ' turn "off" everything else
        End If
    Next

Thanks.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could change the appearance of the PictureBox somehow:

Private Sub picThumb_Click(Index As Integer)
    Dim i As Integer
    For i = picThumb.LBound To picThumb.UBound
        If i = Index Then
            picThumb(i).Appearance = 1 ' 3D
            picThumb(i).BorderStyle = 1 ' Fixed Single
        Else
            picThumb(i).Appearance = 0 ' Flat
            picThumb(i).BorderStyle = 0 ' None
        End If
    Next i
End Sub
0
 
tvtechAuthor Commented:
Thanks I_M.

I know I sound dense and have not explained fully. I did the BorderStyle change earlier, but it's fairly neglible on small thumbnails, such as mine.
Basically, I want to either put a new outline around the selected image (Say using Line, or Shape etc), or otherwise highlight a Background colour, much like a coloured painting frame, if you like. Which would probably require my picThumb() to reside inside a larger Picturebox. Any of those sound doable?

Happy to increase points. :-)

Thanks.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If that isn't noticeable enough, then I think your idea of placing the picturebox inside another and changing the backcolor to make a "border" is the best way to go...
0
 
tvtechAuthor Commented:
That will do just fine, thanks, I_M. Good work.
0
All Courses

From novice to tech pro — start learning today.