Toon posts:

[C#] Icons uit Icon Library

Pagina: 1
Acties:

Verwijderd

Topicstarter
Er zijn verschillende programma's waarmee je een setje icons kan samenvoegen in een icon libary (.ICL)

Heeft iemand echter enig idee hoe je icons uit zo'n icon libary kunt gebruiken in je C# applicatie voor bijvoorbeeld een treeview oid

Ik heb namelijk al een tijdje gezocht maar tot nu toe nog geen succes

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 06-05 14:03

curry684

left part of the evil twins

De online help van m'n Visual Studio.NET heeft net als ik eigenlijk geen idee waar je het over hebt ;)

De algemene manier om treeviews van icons te voorzien is met een ImageList,oftewel System.Windows.Forms.ImageList in .NET:
ImageList is typically used by other controls, such as the ListView, TreeView, or ToolBar. You can add bitmaps, icons, or meta files to the ImageList, and the other controls are able to use the images as they require.
Ik kan verder in heel .NET echt niets vinden over icon libraries zo snel.

Professionele website nodig?


Verwijderd

Wat hij waarschijnlijk wil is uit een *.icl bestand een bepaald icoon eruit halen. De bestandsspecificatie dus.

Als je het nergens kan vinden kan je het eventueel ook zelf extracten. Je hebt twee bekende iconen. Laat een progje ze samenvoegen tot icl en kijk hoe het bestand dan is opgebouwd.

Verwijderd

Topicstarter
Fate heeft het inderdaad goed begrepen. Hoe ik een imagelist aan een treeview koppel dat snap ik wel (zo dom ben ik nou ook weer niet ;) ).

Ik wil inderdaad weten hoe je de icons in een icl bestand kan gebruiken in een c# applicatie

Op het moment even geen tijd om het bovenstaande idee uit te testen, zal het wel zsm uitproberen.

Uiteraard zijn nieuwe ideeen ook welkom :P

Verwijderd

Topicstarter
De oplossing

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace IconHandler
{
    public enum IconSize : uint
    {
        Small = 0x0,
        Large = 0x1 
    }

    public class IconHandler
    {
        [DllImport("Shell32", CharSet=CharSet.Auto)]
        internal extern static int ExtractIconEx (
            [MarshalAs(UnmanagedType.LPTStr)] 
            string lpszFile,       
            int nIconIndex,       
            
            IntPtr[] phIconLarge,  
            IntPtr[] phIconSmall,  
            int nIcons);           

        public static Icon[] IconsFromFile(string Filename,IconSize Size)
        {
            int IconCount = ExtractIconEx(Filename,-1, null,null,0); 
            IntPtr[] IconPtr = new IntPtr[IconCount];

            if (Size == IconSize.Small)
            {
                ExtractIconEx(Filename,0,null,IconPtr,IconCount);
            }
            else
            {
                ExtractIconEx(Filename,0,IconPtr,null,IconCount);
            }

            Icon[] IconList = new Icon[IconCount];

            for (int i = 0; i < IconCount; i++)
            {
                IconList[i] = Icon.FromHandle(IconPtr[i]);
            }

            return IconList;
        }
    }
}