3

I have a resource item (a png file) in my resource dictionary which I'm using in several places. Now I want to use it as application's NotifyIcon. But I don't know how to do this. Have you any idea please?

// my image:

var bitmap = new BitmapImage();
bitmap.UriSource = new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png");

// and I try to do this:

var iconHandle = bitmap.GetHicon(); // but this line doesn't work
var ni = new NotifyIcon {
    Icon = System.Drawing.Icon.FromHandle(iconHandle),
    Visible = true
};
4

1 回答 1

4
var sri = Application.GetResourceStream(
    new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png"));
var bitmap = new Bitmap(sri.Stream);
var handle = bitmap.GetHicon();
var ni = new NotifyIcon {
    Icon = System.Drawing.Icon.FromHandle(handle),
    Visible = true
};
于 2013-05-18T10:37:40.403 回答