更改 C# 语言

发布于 2024-09-10 14:09:18 字数 103 浏览 4 评论 0原文

我正在 Windows 上用 C# 开发多语言程序

如何更改某些操作的 Windows 书写语言...
例如,在焦点事件上从英语更改为阿拉伯语。

谢谢

I am developing a multilingual program in C# on Windows

How to change Windows writing language on certain actions...

e.g. to change from English to Arabic on focus event.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱给你人给你 2024-09-17 14:09:18

要选择全新的区域性,请将 CurrentThread.CurrentCulture 设置为新的区域性,例如设置为法语:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fr-FR");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;

您可以找到预定义的 CultureInfo 名称的列表 此处此处

如果您想更改默认区域性的某些方面,您可以获取当前线程的区域性,使用它的名称创建一个新的 CultureInfo 实例,并通过一些更改设置线程的新区域性,例如更改当前区域性以使用 '欧元符号:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo( System.Threading.Thread.CurrentThread.CurrentCulture.Name);
ci.NumberFormat.CurrencySymbol = "€";
System.Threading.Thread.CurrentThread.CurrentCulture = ci;

To select a whole new culture, set the CurrentThread.CurrentCulture to a new culture, e.g. to set to French:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fr-FR");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;

You can find a list of the predefined CultureInfo names here and here.

If you want to change certain aspects of the default culture, you can grab the current thread's culture, use it it's name to create a new CultureInfo instance and set the thread's new culture with some changes, e.g. to change the current culture to use the 'Euro' symbol:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo( System.Threading.Thread.CurrentThread.CurrentCulture.Name);
ci.NumberFormat.CurrencySymbol = "€";
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
冰火雁神 2024-09-17 14:09:18
Thread.CurrentThread.CurrentCulture = yournewculture;

另请参阅 CurrentUICulture 属性。

Thread.CurrentThread.CurrentCulture = yournewculture;

Also see the CurrentUICulture property.

旧情别恋 2024-09-17 14:09:18

在 load 事件中插入以下代码:

InputLanguage.CurrentInputLanguage =
      InputLanguage.FromCulture(new System.Globalization.CultureInfo("fa-IR"));

In load Event insert the code below:

InputLanguage.CurrentInputLanguage =
      InputLanguage.FromCulture(new System.Globalization.CultureInfo("fa-IR"));
渔村楼浪 2024-09-17 14:09:18

此外,如果您想在运行时刷新所有控件的资源,您将需要使用类似以下内容:

private void RefreshResources(Control ctrl, ComponentResourceManager res)
{
    ctrl.SuspendLayout();
    res.ApplyResources(ctrl, ctrl.Name, CurrentLocale);
    foreach (Control control in ctrl.Controls)
        RefreshResources(control, res); // recursion
    ctrl.ResumeLayout(false);
}

如果您想要更好的示例,请检查 我的博客

In addition, if you want to refresh all the controls' resources at runtime, you will need to use something like this:

private void RefreshResources(Control ctrl, ComponentResourceManager res)
{
    ctrl.SuspendLayout();
    res.ApplyResources(ctrl, ctrl.Name, CurrentLocale);
    foreach (Control control in ctrl.Controls)
        RefreshResources(control, res); // recursion
    ctrl.ResumeLayout(false);
}

If you want a better example check my blog.

辞旧 2024-09-17 14:09:18

这些陈述对我很有帮助:

string myLanguage = "HE-IL";
InputLanguage.CurrentInputLanguage =
   InputLanguage.FromCulture(new System.Globalization.CultureInfo(myLanguage));

This statements were helpful for me:

string myLanguage = "HE-IL";
InputLanguage.CurrentInputLanguage =
   InputLanguage.FromCulture(new System.Globalization.CultureInfo(myLanguage));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文