[]
        
(Showing Draft Content)

GrapeCity.ActiveReports.Design.Designer.ResourceLocator

ResourceLocator Property

ResourceLocator

Gets or sets a value representing the mechanism for locating and retrieving report resources such as images, data sources, and subreports.

Declaration
public ResourceLocator ResourceLocator { get; set; }
Property Value
Type Description
ResourceLocator

An instance of ResourceLocator that is responsible for locating and retrieving resources needed by the report. If not set, the designer uses a default implementation.

Remarks

The ResourceLocator plays a critical role in the report generation process by enabling dynamic resolution of resources at design time and runtime. This property allows for customization of the resource resolution process, which can be essential for applications that store report resources in non-standard locations or need to apply custom logic to resource retrieval.

Setting this property to a custom implementation can provide greater flexibility and control over how resources are located and loaded, thereby accommodating complex application scenarios and resource management strategies.

Examples

This property allows you to define a custom resource locator for accessing resources such as images and subreports from a specific location, whether it's a custom storage solution or a particular directory on the disk. To utilize this feature, you must implement a custom resource locator. See the example below for guidance on implementation:

class MyResourceLocator : ResourceLocator
{
	public override Resource GetResource(ResourceInfo resourceInfo)
	{
		if (resourceInfo.Name == "redSquare.png")
		{
			//Here we draw the image with the red square in the center.
			//You can load the image from file system, or from data base, or from assembly resources.
			var img = new Bitmap(100, 100);
			using var graphics = Graphics.FromImage(img);
			using var redBrush = new SolidBrush(Color.Red);
			graphics.FillRectangle(redBrush, 10, 10, 80, 80);
			var tmpStream = new MemoryStream();
			img.Save(tmpStream, System.Drawing.Imaging.ImageFormat.Png);
			tmpStream.Position = 0;
			return new Resource(tmpStream, new Uri("redSquare.png", UriKind.Relative));
		}
		return new Resource();
	}
}

Then, you can utilize this custom resource locator within the designer.

class MyDesignerForm : Form
{
	public MyDesignerForm()
	{
		InitializeComponent();
		//note the designer must be added to the form and its name have to be '_designer'.
		_designer.ResourceLocator = new MyResourceLocator();
	}
}