flobadob
flobadob

Reputation: 2872

Using a Windows Forms icon in WPF

I've got this WPF code which works...

Uri iconUri = new Uri("pack://application:,,,/media/images/VS.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

I'm using a windows forms notifyIcon control in my WPF app, and I now need to assing the Icon to it. How do I get from my WPF icon to a System.Drawing.Icon ?

Upvotes: 1

Views: 2443

Answers (2)

Brent
Brent

Reputation: 1773

I use the following method:

// Setup the new NotifyIcon
System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Text = "Name of Application";
notifyIcon.Icon = new System.Drawing.Icon("media/images/VS.ico");
notifyIcon.Visible = true;

Make sure you add a reference to System.Drawing.

Upvotes: 2

JustABill
JustABill

Reputation: 1559

Imaging.CreateBitmapSourceFromHBitmap

I use it like:

return Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

where source is a Bitmap, which you can get by calling your Icon's .ToBitmap() method.

Upvotes: 0

Related Questions