|
-
Feb 7th, 2004, 12:44 PM
#1
Thread Starter
Registered User
file icon to treeNode image
how do i add an icon to a treenode?
i don't want to necessarily use an imagelist...
-
Feb 8th, 2004, 03:34 AM
#2
Why would you NOT want to use an imagelist? It may be easier to dynamically add images to the imagelist and then add the treenode using that imageindex.
-
Feb 8th, 2004, 09:17 PM
#3
Thread Starter
Registered User
i have a treeview, which is merely a file/folder structure. when i add a file, i want to associate it with its icon.
so, when i find a file, i add the treenode and then i get the icon associated with the file. if i use an imagelist then i need to see if that icon is already part of the imagelist and find its index... thats tedious.
if you have a thought how i might more effectively use an imagelist tell me, because right now it dosn't make much sense to me for what i'm trying to do.
-
Feb 9th, 2004, 12:58 PM
#4
Frenzied Member
check this thread out
this should answer your question.
-
Feb 9th, 2004, 06:39 PM
#5
Thread Starter
Registered User
Code:
Private Declare Function Extract_Icon Lib "shell32.dll" Alias "ExtractIconEx" (ByVal lpszExeFileName As String, ByVal nIconIndex As Integer, ByRef hIconLarge As IntPtr, ByRef hIconSmall As IntPtr, ByVal IconCount As Integer) As IntPtr
Public Function ExtractIconFromFile(ByVal Filename As String, ByVal IconIndex As Integer, ByVal IconSize As iSize) As Drawing.Icon
Dim hIconLarge As IntPtr
Dim hIconSmall As IntPtr
Extract_Icon(Filename, IconIndex, hIconLarge, hIconSmall, 1)
If IconSize = iSize.Large Then
Return Drawing.Icon.FromHandle(hIconLarge)
Else
Return Drawing.Icon.FromHandle(hIconSmall)
End If
End Function
ok, so now i can get the icon of a file or folder. how do i add that icon to a treenode? i have to first convert it to an image file ifi want to use an imageList...
-
Feb 9th, 2004, 07:17 PM
#6
You don't need to convert it to a file to add it to an imagelist. It returns an icon object and that can be added directly to theh imagelist at runtime:
ImageList1.Images.Add(myIcon)
The only hard part would be finding out if it is already in the list. The easiest way around that would probably be to track which extensions you already have images for:
Public ht As New HashTable 'class level scope
ImageList1.Images.Add(myIcon)
ht.Add(extension, myIcon)
'or
ht.Add(extension, myIconIndex)
Then you could retrieve the image or index via the file extension since it is the key for the hashtable.
Last edited by Edneeis; Feb 9th, 2004 at 07:25 PM.
-
Feb 10th, 2004, 08:56 PM
#7
Thread Starter
Registered User
in the code in my last post, what is iSize.large??? its underlined in my version and not recognized.
-
Feb 11th, 2004, 02:36 PM
#8
Frenzied Member
try putting this in your "imports" section:
System.Drawing.Icon
look up the icon class and it may have further infor you could use.
also, in that post you got the code from, there is a structure that defines iIcon:
VB Code:
Private Structure SHFileInfo
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
-
Feb 11th, 2004, 02:50 PM
#9
Thread Starter
Registered User
imports system.drawing.icon dosn't help?
the size class also dosn't have a large property.
what size is probably meant by large? then i can just compare width and height properties...
-
Feb 11th, 2004, 03:59 PM
#10
Hi Marvin.
iSize is just a homemade enum, to determine if the function should return the large or the small icon.
That is why your VB doesn't recognize it.
If you now you always want the small just remove the if statement and use the Return Drawing.Icon.FromHandle(hIconSmall)
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|