BaseFormDynamicStringLocalization Property

Gets or sets the dynamic string localization strategy of the form. It allows using potentially auto-generated string resources from .resx files.

See the online help for an example.

Definition

Namespace: KGySoft.WinForms.Forms
Assembly: KGySoft.WinForms (in KGySoft.WinForms.dll) Version: 5.0.1
C#
[DefaultValueAttribute(DynamicStringLocalization.Disabled)]
public DynamicStringLocalization DynamicStringLocalization { get; set; }

Property Value

DynamicStringLocalization

Remarks

  Note

This property offers a different localization strategy to the Localizable property of the Windows Forms designer, and it is not recommended to use them both together.

Unlike the Localizable property of the Windows Forms designer, this property affects the localization of the string properties only, and basically determines the behavior of the default ApplyStringResources implementation. You still can apply non-string resources without enabling Localizable by overriding the ApplyResources method, whose default implementation just calls ApplyStringResources.

When this property is set to Disabled, no automatic localization occurs. To localize string resources programmatically, you can override the ApplyStringResources method.

The ApplyResources method is called automatically when the form is loaded for the first time, but you can explicitly call it whenever you need to re-apply the resources (or ApplyStringResources to re-apply the string resources only), for example when the display language changes.

When the value of this property is not Disabled, then the base ApplyStringResources implementation calls the LocalizationHelper.ApplyStringResources method, which traverses the controls of the form recursively, and invokes the LocalizationRequested event for each localizable string property of the controls. If this property is set to Custom, then you must handle the event to provide localization for the controls programmatically. When the LocalizationRequested event does not handle a request, using LocalScope or AssemblyScope allow using .resx files placed in the Resources folder of the deployment directory that can be automatically generated for the first time when a localization request is made for a culture that has no resource file yet.

Using LocalScope or AssemblyScope works only if the invariant resource set exists for the form or user control. Only the properties that have an entry in the invariant resource set will be localized automatically.
See also the DynamicStringLocalization enumeration for details.

Examples

The following image shows a form of an application that allows localizing its resources to any language, and applying them at run-time:

A resource editor form in the KGySoft.WinForms.Example application

  Tip

The image above is from the example application. At the Releases page of the project repository you can download it as executable binaries as well. The example is located under the Misc Tests / Dynamic localization example menu, which allows testing the various DynamicStringLocalization settings as well.

See Also