// Set the form's culture. private void SetCulture(string culture) { // Make the CultureInfo. CultureInfo culture_info = new CultureInfo(culture);
// Make a ComponentResourceManager. ComponentResourceManager component_resource_manager = new ComponentResourceManager(this.GetType());
// Apply resources to the form. component_resource_manager.ApplyResources( this, "$this", culture_info);
// Apply resources to the form's controls. foreach (Control ctl in this.Controls) { component_resource_manager.ApplyResources( ctl, ctl.Name, culture_info); } }
The code makes a new CultureInfo object to represent the culture. It then makes a ComponentResourceManager for the culture and uses its ApplyResources method to load the culture-specific resources for the form and its controls.
The following code shows how the example loads its resources for English or German when you select a radio button.
(This example actually isn't localized for English but that's what I used when making the default localization so that's what you get if you select en-EN or any other culture for which it isn't localized. For example, try fr-FR or es-MX.)
Comments