Anees
Anees

Reputation: 873

C# Loading Icons in Runtime

I'm having about 200 icons ,which I wanted to display in a treeview on Runtime. Can anyone suggest me the best way to do this.

Do i need to store "relative path" of each icon in "app.config" and load?? or can I compile all the icons to a dll and extract from there...

or any other best suited idea..?

Thanks in advance.

Upvotes: 0

Views: 2518

Answers (3)

Oliver
Oliver

Reputation: 45071

Another option would be to add an ImageList to your Form in Design-Mode and the Click 'Choose images' from the Properties Menu. In this dialog you can simply select all your icons and they will be added to your ImageList.

At your code you can access these icons by

imageList.Images[int index]
imageList.Images[string key]

Upvotes: 0

Richard
Richard

Reputation: 108975

Best option: embedded resources in the assembly.

But it does mean changing the icons will require a recompile (the selection of which icons are used could be configurable).

Upvotes: 1

Henri
Henri

Reputation: 5103

You should add the icons to the resources of your project, and then it becomes available in the class Properties.Resources.

So you dont have to store any paths.

Only drawback is that you need to compile again if you want to change the icons.

Upvotes: 1

Related Questions