代码之家  ›  专栏  ›  技术社区  ›  flobadob

在WPF中使用Windows窗体图标

  •  1
  • flobadob  · 技术社区  · 14 年前

    我有这个WPF代码…

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

    我正在我的WPF应用程序中使用Windows窗体NotifyIcon控件,现在我需要将该图标分配给它。如何从wpf图标转到system.drawing.icon?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Brent    14 年前

    我使用以下方法:

    // 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;
    

    确保添加了对System.Drawing的引用。

        2
  •  0
  •   JustABill    14 年前

    Imaging.CreateBitmapSourceFromHBitmap

    我用它像:

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

    其中源是 Bitmap ,您可以通过拨打 Icon .ToBitmap() 方法。