我正在开发一个我想支持本地化的应用程序。我已经实现了卫星程序集概念来实现本地化,但问题是它将根据所选语言在运行时加载/渲染所有控件的文本,这使得我的应用程序加载非常缓慢。
现在我的问题是:有没有更好的方法可以让我在加载时更新我的所有主窗体控件而不会延迟/闪烁。
我正在使用 c#.net Winforms 开发应用程序。
我的项目结构:
这是我尝试过的[示例代码]:
注意:这很好用,因为这个示例应用程序只包含很少的控件,但我的实际应用程序包含太多控件,这些控件在加载时肯定会延迟/闪烁。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;
namespace Localization
{
public partial class Form1 : Form
{
#region constants
const String DEFAULT_CULTURE = "en-US";
#endregion
ResourceManager resourceManager = null;
public Form1()
{
InitializeComponent();
resourceManager = new ResourceManager("Localization.Resources", Assembly.GetExecutingAssembly());
}
private void cmbSelectLanguages_SelectedIndexChanged(object sender, EventArgs e)
{
String languageCode = "";
switch (cmbSelectLanguages.SelectedItem.ToString())
{
case "German": languageCode = "de-DE";
break;
case "French": languageCode = "fr-FR";
break;
case "English": languageCode = DEFAULT_CULTURE;
break;
default: languageCode = DEFAULT_CULTURE;
break;
}
SetCulture(languageCode);
SetControlsText();
}
private void SetCulture(String languageCode)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageCode);
}
private void Form1_Load(object sender, EventArgs e)
{
//set the default languge to US-English while loading the form
SetCulture(DEFAULT_CULTURE);
SetControlsText();
}
private void SetControlsText()
{
lblCulture.Text = " " + System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
lblUserName.Text = resourceManager.GetString("lblUsername");
lblPassword.Text = resourceManager.GetString("lblPassword");
btnLogin.Text = resourceManager.GetString("lblLogin");
btnCancel.Text = resourceManager.GetString("lblCancel");
lblChooseLanguage.Text = resourceManager.GetString("lblChooseLanguage");
lblLoginTitle.Text = resourceManager.GetString("lblUserLogin");
pic.Image = (Image)resourceManager.GetObject("Login");
}
private void btnCancel_Click(object sender, EventArgs e)
{
}
private void btnLogin_Click(object sender, EventArgs e)
{
}
}
}