Home >Backend Development >C++ >How Do I Create and Use Resources in .NET?

How Do I Create and Use Resources in .NET?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-21 07:06:10320browse

How Do I Create and Use Resources in .NET?

.NET Resource Management

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn