Solved

Retaining index of current image

Posted on 2006-11-20
8
260 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now