zoukankan      html  css  js  c++  java
  • C# Winform 国际化

    1、在Form的language属性选择中文,来制作中文界面

    保存后,设置界面标题会变成如下所示,并且会出现一个zh-CN的资源文件,打开resx文件可看到相应内容

    2、将Form的language属性改为英文,其余步骤如第1步,即可生成英文资源文件 

    3、添加代码完成切换

    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.Threading;
    
    namespace LanguageDemo
    {
        public partial class Form1 : Form
        {
    
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
            // 遍历控件,并根据资源文件替换相应属性
            private void ApplyResource()
            {
                foreach (Control ctl in this.Controls)
                {
                    resources.ApplyResources(ctl, ctl.Name); 
                }
                this.ResumeLayout(false);
                this.PerformLayout();
                resources.ApplyResources(this, "$this");
            } 
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                string s = System.Globalization.CultureInfo.InstalledUICulture.Name; //获取当前系统的语言
                Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(s);
                ApplyResource();
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
                }
                else
                {
                    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");
                }
                ApplyResource();
            }
        }
    }

    原文:https://blog.csdn.net/jack____wen/article/details/79614712 

  • 相关阅读:
    c# Queue实现生产者(Producer)消费者(Consumer)模式
    无法连接到已配置的web服务器
    2018年新年计划
    md5加密、Des加密对称可逆加密、RSA非对称可逆加密、https单边验证、银行U盾双边认证
    通过HTTP协议实时获取微信聊天记录
    c#委托与事件
    c#异步多线程
    详细解读PHP时区修改正确方法
    Mysql分库分表方案
    关于Windows下安装mongodb和加入Windows系统启动项
  • 原文地址:https://www.cnblogs.com/qiyecao/p/10637403.html
Copyright © 2011-2022 走看看