Solved

Retaining index of current image

Posted on 2006-11-20
8
265 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
  • 4
  • 4
8 Comments
 
LVL 85

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 85

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 85

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 85

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Windows 10 start screen issues 9 55
MS Access - Capture pressed key onclick 4 42
MsgBox 2 59
MS Date Picker 64 bit 32 bit issue 12 61
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

828 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