Create resource:
In Solution Explorer, right-click your project and select Properties. Under the Resources tab, click the first button to select a resource type and then select Icon. Use the Add Resource button to create a new icon or import an existing icon. Double-click the added resource to edit it.
Use resources:
To access resources in code, use the Properties.Resources static class. For example:
<code class="language-csharp">using System.Drawing; // 加载“RedIcon”资源 Image redIcon = Properties.Resources.RedIcon; // 将 NotifyIcon 的图标设置为加载的资源 notifyIcon.Icon = redIcon;</code>
To change the icon dynamically, assign a new resource to the NotifyIcon's Icon property:
<code class="language-csharp">paused = !paused; if (paused) notifyIcon.Icon = Properties.Resources.RedIcon; else notifyIcon.Icon = Properties.Resources.GreenIcon;</code>
The above is the detailed content of How Do I Create and Use Resources in .NET?. For more information, please follow other related articles on the PHP Chinese website!