I made Custom Control and I added a new property that is meant to point to a Resource.
How can I get the value, which is set in the Form Designer, of this property from another property of the Custom Control?
When I try to read it, the value it return is null
.
My code related to the of Custom Control and the mentioned property:
class ResourceLabel : Label
{
private string resourceKey;
[Category("Appearance")]
[Browsable(true)]
[Description("Sets the resource key for localization")]
public string ResourceKey
{
get { return resourceKey; }
set {
if (resourceKey != value) {
resourceKey = value;
Invalidate();
}
}
}
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]
public override string Text
{
if (base.Text != value) {
Console.WriteLine($"Test: {ResourceKey}");
if (ResourceKey != null) {
var locale = CultureInfo.GetCultureInfo(Properties.Settings.Default.Language);
var textFromResource = Resources.ResourceManager.GetString(ResourceKey, locale);
base.Text = textFromResource;
}
else {
base.Text = value;
}
}
}
}
This string Console.WriteLine($"Test: {ResourceKey}");
returns null
.