Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Image 1

Status
Not open for further replies.

Zahir

Programmer
Sep 16, 1999
28
PK
Hi..

I have multiple images on a floppy, i want to show them in one go on a form in List view or any other control, Pls help it is urgent. and if u have a better solution pls guide me.

Thanks

Regards
 
on your form, make a control array of picture boxes. That allows you to add and remove at runtime. You have to keep one control on the form, but you can hide it if you're not using it.

Use a scripting.filesystemobject to get the directory and count the files. That gives you the number of picture boxes you need. Use that value to determine the size of each picture box or if you'll possibly need to add a "Next ->" buttion.

Use the file system object to loop through the files in the directory and read the file names, maybe test to be sure they are valid picture types.

You could store all of the picture filenames in an array. Then load each image into the corresponding picture box.

For i = 0 to NumPictures - 1
Picture1(i).Picture = LoadPicture(arPictureNames(i)
next i

You'd get a bunch of thumbnails. Put the picture name in the Tag property for each picture box then you've got it available if you want to enlarge the thumbnail, have a suitable click event.

Private Sub Picture1_Click(index as long)
dim frm as frmEnlargePic
'frmEnlargePic = form with picture box and close button
dim strPic as string

strPic = Picture1(index).Tag
set frm = new frmEnlargePic
frmEnlargePic.View(strPic) 'Lets you pass a parameter
end sub

On frmEnlargePic
Public Function View (ByVal strPic as String) as Boolean
Picture1.picture = LoadPicture(strPic)
Me.Show vbModal
View = true
end Function

something like that

scarfhead


 
Here's another solution that will work dynamically, no matter how many picture files exist in the given directory.

Create a form, with a ListView (ListView1), an ImageList (ImageList1) and a ListBox(lstFiles).

Code:
Private Sub Form_Load()
    Dim sPath As String
    
    'Set properties for controls
    lstFiles.Visible = False
    
    'Set Thumbnail Size
    ImageList1.ImageHeight = 48
    ImageList1.ImageWidth = 48
    
    'Set path for files
    sPath = "E:\winnt\"
    
    'Get list of files
    LoadFilestoList lstFiles, sPath, "*.bmp"
    
    'Load all BMP files to imagelist
    
    For i = 0 To lstFiles.ListCount - 1
        ImageList1.ListImages.Add i + 1, lstFiles.List(i), LoadPicture(sPath & lstFiles.List(i))
    Next i
    
    'Set Listview ImageList to current ImageList
    ListView1.Icons = ImageList1
    
    'Add all files to listview
    'NOTE: I know this seems redundant, but you have to initialize
    'the image list FIRST before adding it as the ICONS source
    'for the ListView.
    For i = 0 To lstFiles.ListCount - 1
        ListView1.ListItems.Add i + 1, lstFiles.List(i), lstFiles.List(i), lstFiles.List(i)
    Next i
End Sub

Add the following code to a Code Module:

Code:
Public Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Const DDL_ARCHIVE = &H20
Public Const DDL_DIRECTORY = &H10
Public Const DDL_FLAGS = DDL_ARCHIVE Or DDL_DIRECTORY
Public Const LB_DIR = &H18D

Public Sub LoadFilestoList(List As Control, Path As String, Extension As String)
    Dim PathSpec As String
    Dim r As Long
    PathSpec = Path & Extension
    r = SendMessageStr(List.hwnd, LB_DIR, DDL_FLAGS, PathSpec)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top