런타임에 양식의 모든 컨트롤 언어를 변경하는 방법이 있습니까?양식의 모든 컨트롤에서 텍스트 언어를 변경하는 방법
예를 들어 양식에 버튼이 있고 "Hello"라는 텍스트가 있습니다. 런타임시 어떻게 다른 언어로 변경할 수 있습니까? 내가 설정할 수있는 모든 언어를 동적으로. 그것을 할 수있는 방법이 있습니까 ??
답변을 찾았지만 작동하지 않는 것 같아서 cultureinfo와 관련이있는 것으로 보입니다. 그것을하는 방법 어떤 제안? 양식에 볼 수 있습니다 컨트롤과 당신이 말할 버튼의 텍스트 또는 변경 런타임에서 필요한 문자열 :
이
은 변환해야 것의 두 종류가 있습니다 내 코드public partial class Form1 : BaseLanguageForm
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.TriggerLanguageChange("fr-FR");
}
}
public class LanguageArgs : EventArgs
{
string _languageSymbol;
/// <summary>
/// Gets the language symble.
/// </summary>
public string LanguageSymbol
{
get { return _languageSymbol; }
}
/// <summary>
/// Initializes a new instance of the <see cref="LanguageArgs"/> class.
/// </summary>
/// <param name="symbol">The symbol.</param>
public LanguageArgs(string symbol)
{
this._languageSymbol = symbol;
}
}
public class BaseLanguageForm : Form
{
/// <summary>
/// Triggers the language change event.
/// </summary>
/// <param name="languageSymbol">The language symbol.</param>
protected void TriggerLanguageChange(string languageSymbol)
{
if (Form1.onLanguageChanged != null)
{
LanguageArgs args = new LanguageArgs(languageSymbol);
Form1.onLanguageChanged(this, args);
}
}
/// <summary>
/// This should be triggered whenever the combo box value chages
/// It is protected, just incase you want to do any thing else specific to form instacne type
/// </summary>
protected static event EventHandler<LanguageArgs> onLanguageChanged;
/// <summary>
/// This will be called from your form's constuctor
/// (you don't need to do anything, the base class constuctor is called automatically)
/// </summary>
public BaseLanguageForm()
{
//registering to the event
BaseLanguageForm.onLanguageChanged += new EventHandler<LanguageArgs>(BaseLanguageForm_onLanguageChanged);
}
/// <summary>
/// The function that was regidtered to the event
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
void BaseLanguageForm_onLanguageChanged(object sender, LanguageArgs e)
{
string lang = e.LanguageSymbol;
foreach (Control c in this.Controls)
{
ComponentResourceManager crm = new ComponentResourceManager(typeof(Form1));
crm.ApplyResources(c, c.Name, new CultureInfo(lang));
}
}
}
고전적인 방법 양식의 언어를 변경하는 것입니다. Form 속성입니다.) 이것은 당신이 설정 한 모든 언어에 대한 폼의 복사본을 생성하고 모든 컨트롤을 번역 할 수 있고, 필요하다면 레이아웃을 변경할 수 있습니다. 런타임에 당신이 언어를 변경할 때 다른 폼이 보여 질 것입니다. – TaW
우리에게 보여준 방법이 나에게 맞는 것 같습니다. 하지만 어리석은 질문은 각 요소에 대해 올바른 번역 문자열이있는 리소스 파일이 있습니까? – frikinside
나는 내 질문을 가지고 있지 않다. 나는 어떻게 런타임에 텍스트를 번역 할 수 있는가? – bRaNdOn