ActiveReports 19 .NET Edition
MESCIUS.ActiveReports.Design.Win Assembly / GrapeCity.ActiveReports.Design Namespace / Designer Class / ResourceLocator Property
Example

In This Topic
    ResourceLocator Property (Designer)
    In This Topic
    Gets or sets the resource locator implementation that used to locate the custom resources.
    Syntax
    'Declaration
     
    Public Property ResourceLocator As ResourceLocator
    public ResourceLocator ResourceLocator {get; set;}

    Property Value

    An instance of GrapeCity.ActiveReports.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.

    Example
    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: Then, you can utilize this custom resource locator within the designer.
    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();
    	}
    }
    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();
    	}
    }
    See Also