ComponentResourceManager resources = new ComponentResourceManager(typeof(Type));
The argument to the constructor is wrong, you are telling it to find the resources for System.Type. Which is why it is complaining that it can't find "System.Type.resources". It will never find those.
You need to pass the type of the form that you actually want to localize. Use this.GetType()
instead. Albeit that this probably will just localize your Options form and not the rest of the windows in your app. You could iterate Application.OpenForms() instead. It is also necessary to apply the localization to all the controls. Not just the ones on the form, also the ones that are located inside containers like panels. Thus:
private static void ChangeLanguage(string lang) {
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
foreach (Form frm in Application.OpenForms) {
localizeForm(frm);
}
}
private static void localizeForm(Form frm) {
var manager = new ComponentResourceManager(frm.GetType());
manager.ApplyResources(frm, "$this");
applyResources(manager, frm.Controls);
}
private static void applyResources(ComponentResourceManager manager, Control.ControlCollection ctls) {
foreach (Control ctl in ctls) {
manager.ApplyResources(ctl, ctl.Name);
applyResources(manager, ctl.Controls);
}
}
Be careful with wiz-bang features like this. Nobody actually changes their native language while they are using your program.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…