Class ResourceHelper
Provides utility methods for loading and manipulating embedded assembly resources.
Inheritance
Inherited Members
Namespace: Telerik.WinControls
Assembly: Telerik.WinControls.dll
Syntax
public static class ResourceHelper
Remarks
ResourceHelper contains static methods for accessing embedded resources from assemblies, particularly images and cursors that are embedded as manifest resources. It provides safe resource loading with proper exception handling and resource disposal.
Key features include:
- Safe loading of embedded bitmap images with automatic memory management
- Cursor creation from embedded cursor resource files
- Proper exception handling with debug output for troubleshooting
- Automatic resource stream disposal to prevent memory leaks
- Assembly-based resource resolution using type information
This class is commonly used throughout Telerik controls for loading embedded images, icons, cursors, and other resources that are compiled into the assembly as manifest resources.
Methods
CursorFromResource(Type, String)
Creates a new cursor from an embedded resource in the assembly containing the specified type.
Declaration
public static Cursor CursorFromResource(Type type, string resourceName)
Parameters
System.Type
type
A type from the assembly that contains the embedded resource. |
System.String
resourceName
The fully qualified name of the embedded cursor resource (including namespace). |
Returns
System.Windows.Forms.Cursor
A new System.Windows.Forms.Cursor instance loaded from the embedded resource, or |
Remarks
This method safely loads a cursor from an embedded manifest resource by:
- Obtaining the assembly from the specified type
- Opening a stream to the manifest resource
- Creating a cursor directly from the stream
- Ensuring proper resource disposal regardless of outcome
The resource should be a valid cursor file (.cur) embedded as a manifest resource. The resource name should include the full namespace path, similar to other embedded resources.
Exception handling ensures that any loading errors are logged to debug output for
troubleshooting, while maintaining application stability by returning null
on failure.
ImageFromResource(Type, String)
Creates a new bitmap image from an embedded resource in the assembly containing the specified type.
Declaration
public static Bitmap ImageFromResource(Type type, string resourceName)
Parameters
System.Type
type
A type from the assembly that contains the embedded resource. |
System.String
resourceName
The fully qualified name of the embedded resource (including namespace). |
Returns
System.Drawing.Bitmap
A new System.Drawing.Bitmap instance loaded from the embedded resource, or |
Remarks
This method safely loads a bitmap image from an embedded manifest resource by:
- Obtaining the assembly from the specified type
- Opening a stream to the manifest resource
- Creating a temporary bitmap from the stream
- Creating a new bitmap copy to ensure proper memory management
- Disposing of temporary resources and streams
The resource name should include the full namespace path. For example, if an image is in the "Resources" folder of a project with namespace "MyProject", the resource name would be "MyProject.Resources.image.png".
Exception handling ensures that any loading errors are logged to debug output, and all resources are properly disposed of regardless of success or failure.