dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Selecting File from File List Box

Question:
I put a drive box, a directory list box, and a file list box on the form, with the intention of being able to select an *.ico file from the file list, and have it display the relevant icon in a picture box which I also had on the form. Please help before I go bald !!!

Answer:
Here's the sample code that demonstrates this. On your form put a DriveBox, DirBox, FileListBox and Picture control. Make sure to set the AutoSize property on the Picture control to True and the Pattern property on your FileListBox to *.ico.

'the first two subs just  keep the DriveBox, DirBox and FileList box synced.
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

'this is the sub that will display the icon in the picture control when double-clicked
Private Sub File1_DblClick()
Dim pic As String

pic = Dir1.Path       'this puts the path where the icon file is into the pic variable
pic = FixPath$(pic) 'FixPath$ code is below.  It simply adds a trailing backslash if needed.
pic = pic & File1.filename    'this adds the icon's filename to the end of the pic variable
Picture1.Picture = LoadPicture(pic)  'and this loads it into your picture control

End Sub

'copy and paste this into your form's General/Declarations section
Function FixPath$(Test$)
'sticks a backslash on the end of test$ if there's not one there already
If Right$(Test$, 1) <> "\" Then Test$ = Test$ + "\"
FixPath$ = Test$
End Function
This code should work equally well with VB3.0 and VB4.0.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date