'Declaration Public Property ResourceLocator As ResourceLocator
public ResourceLocator ResourceLocator {get; set;}
'Declaration Public Property ResourceLocator As ResourceLocator
public ResourceLocator ResourceLocator {get; set;}
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.
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(); } }