3

I have a Icon.ico and in the Properties the Build Action is "Resource"...

I want to load that Icon in the Application..

I did something like this:

Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Icon.ico"));

that didnt worked (it says "Value of 'null' is not valid for 'stream'.")

What can I do?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
eMi
  • 5,540
  • 10
  • 60
  • 109
  • 2
    This should help you: http://stackoverflow.com/questions/74466/how-do-i-use-an-icon-that-is-a-resource-in-wpf – Jan K. Oct 24 '11 at 09:20

1 Answers1

8

try using Application.GetResourceStream method

using(Stream stream = Application.GetResourceStream(new Uri("/MyNameSpace.ico")).Stream)
{
    Icon myIcon = new System.Drawing.Icon(stream);
}

more information from MSDN

VoteCoffee
  • 4,692
  • 1
  • 41
  • 44
Damith
  • 62,401
  • 13
  • 102
  • 153
  • Thanks I think that would work also well... I did this: `Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/INBOS_Starter;component/Inbos_Starter_Icon.ico")).Stream;` – eMi Oct 24 '11 at 09:28