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 

  • 相关阅读:
    主引导扇区的理解
    敏捷的思考
    架构学习笔记
    操作系统笔记
    Docker学习笔记
    技术面试-国外人谈经验
    硬盘的原理学习
    linux压缩和解压命令总结
    好的技术团队和差的技术团队的区别在于技术架构前瞻性和适应变化的能力
    管理者的本质其实就是一个服务者,服务下属的
  • 原文地址:https://www.cnblogs.com/qiyecao/p/10637403.html
Copyright © 2011-2022 走看看