How do I use an icon that is a resource in WPF?

前端 未结 5 496
北荒
北荒 2020-11-29 20:06

I have a .ico file that is embedded as a resource (build action set to resource). I am trying to create a NotifyIcon. How can I reference my icon?

notifyIc         


        
5条回答
  •  無奈伤痛
    2020-11-29 21:03

    A common usage pattern is to have the notify icon the same as the main window's icon. The icon is defined as a PNG file.

    To do this, add the image to the project's resources and then use as follows:

    var iconHandle  = MyNamespace.Properties.Resources.MyImage.GetHicon();
    this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(iconHandle);
    

    In the window XAML:

    
    

提交回复
热议问题