Solved

Retaining index of current image

Posted on 2006-11-20
8
268 Views
Last Modified: 2010-04-30
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.

0
Comment
Question by:tvtech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17984504
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
 

Author Comment

by:tvtech
ID: 17984634
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
 

Author Comment

by:tvtech
ID: 17984647
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17985351
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
 

Author Comment

by:tvtech
ID: 17985478
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 450 total points
ID: 17988394
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17988404
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
 

Author Comment

by:tvtech
ID: 17991668
That will do just fine, thanks, I_M. Good work.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question