如何创建可以更改打开对话框的显示语言的多语言窗体? [英] How to create a multilingual windows form that can change the display language of open dialog box?

查看:84
本文介绍了如何创建可以更改打开对话框的显示语言的多语言窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天



如何创建可以更改打开对话框的显示语言的多语言窗体?我有一个表单应用程序,并希望用户改变显示语言。这是我的代码,到目前为止我可以更改表单控件,包括菜单项,我无法更改显示对话框按钮文本(确定,取消,中止...)所以我决定创建自己的正常窗口窗体到充当对话框,它工作正常。

我选择表单的Localizable属性为True,并为每种语言创建语言资源文件(resx)。它工作正常,即使我必须重新启动应用程序使语言生效,我也没有问题。

问题是如何更改打开的对话框,因为我无法创建自定义的。假设我想要一个用户可以浏览并打开图像的打开对话框,它仍然以英文显示(文件名,打开和取消按钮......)



这是我的代码:



使用System.Data;

使用System.Drawing;

使用System .Linq;

使用System.Text;

使用System.Threading.Tasks;

使用System.Windows.Forms;

使用System.Globalization;

使用System.Threading;

使用System.Resources;

使用System.Net.NetworkInformation;



名称空间语言

{

公共部分类Form1:表格

{

公共字符串语言= Properties.Settings.Default.Langue;



public Form1()

{< br $>


Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);

InitializeComponent();

}



private void englishMenuItem_Click(object sender,EventArgs e)

{



language =" en" ;;

englishMenuItem.Checked = true;

germanMenuItem.Checked = false;

frenchMenuItem.Checked = false;



//在设置中保存用户选择

Properties.Settings.Default.Langue =" en";

Properties.Settings .Default.Save();

}





private void frenchMenuItem_Click(object sender,EventArgs e)

{

// ChangeLanguage(" fr-FR");

language =" fr-FR";

frenchMenuItem.Checked = true;

germanMenuItem.Checked = false;

englishMenuItem.Checked = false;







//在设置中保存用户选择

Properties.Settings.Default.Langue =" fr-FR";

Properties.Settings.Default.Save();

}







非常感谢

Good day

How to create a multilingual windows form that can change the display language of open dialog box?I have a form application and would like the user to change the language of display. Here is my code, so far I can change the form controls including the menu item, I couldn't change the show dialog boxes button texts (ok, cancel, abort...) so I decide to create my own normal window form to act as a dialog box, and it's working fine.
I selected the Localizable property of the form to True and created a language resource file (resx) for each language. It working fine even if I have to restart the application for the language to take effect, I don't have a problem with that though.
The problem is how to change the open dialog box, because I couldn't create a custom one. Let say I want an open dialog box where a user can browse and open an image, it still display in English (File name, Open and Cancel Button...)

Here is my code:

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Net.NetworkInformation;

namespace Language
{
public partial class Form1 : Form
{
public string language = Properties.Settings.Default.Langue;

public Form1()
{

Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
InitializeComponent();
}

private void englishMenuItem_Click(object sender, EventArgs e)
{

language = "en";
englishMenuItem.Checked = true;
germanMenuItem.Checked = false;
frenchMenuItem.Checked = false;

// Save user choice in settings
Properties.Settings.Default.Langue = "en";
Properties.Settings.Default.Save();
}


private void frenchMenuItem_Click(object sender, EventArgs e)
{
// ChangeLanguage("fr-FR");
language = "fr-FR";
frenchMenuItem.Checked = true;
germanMenuItem.Checked = false;
englishMenuItem.Checked = false;



// Save user choice in settings
Properties.Settings.Default.Langue = "fr-FR";
Properties.Settings.Default.Save();
}



Thank you very much

推荐答案

我过去对这个主题的回答几乎涵盖了你需要知道的所有主要想法:

如何使用3种语言的单个resx文件 [ ^ ],

winforms中的全球化 [ ^ ],

winform .net 中的全球化/本地化问题[ ^ ]。



还有这一个:复选框的全球化 [ ^ ]。



显示语言可以在运行时通过更改切换当前UI线程的文化和UI文化以及无效/刷新视图。将自动从您提供的选项中拾取和加载所需的附属程序集;如果缺少所需的卫星装配,将自动使用后备机制。这是基于它们的那些卫星组件和本地化/全球化的整体想法。



参见:

http://msdn.microsoft.com/en-us/library/9xdxwwkc%28v=vs。 110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/y99d1cd3%28v=vs.110%29.aspx [ ^ ]。



祝你好运。

-SA
Nearly all the main ideas you will need to know are covered in my past answers on the topic:
How to use a Single resx file for 3 languages[^],
globalization in winforms[^],
globalization/localization problem in winform .net[^].

And also this one: Globalization of Checkboxes[^].

The display language can be switched during runtime by changing the culture and UI culture of the current UI thread and invalidation/refreshing the view. The required satellite assemblies would be picked up and loaded, from the choices you provided, automatically; in case of missing required satellite assembly the fallback mechanism will be automatically used. This is the whole idea of those satellite assemblies and localization/globalization based on them.

See also:
http://msdn.microsoft.com/en-us/library/9xdxwwkc%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/y99d1cd3%28v=vs.110%29.aspx[^].

Good luck.
—SA


感谢您的留言,但我仍在努力,我不是在C#中的期望,你能给我一个关于如何做到这一点的简单代码示例吗?

谢谢
Thank you for your message, but i am still struggling, I am not an expect in C#, could you provide me with just a simple code example on how to do this?
Thanks


这篇关于如何创建可以更改打开对话框的显示语言的多语言窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆