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 

  • 相关阅读:
    Java Jsch SFTP 递归下载文件夹
    spring-jms,spring-boot-starter-activemq JmsTemplate 发送方式
    Spring Boot 入门之消息中间件篇(转发)
    Springboot websocket使用
    FinalCutPro快捷键
    基本CSS布局三
    As Simple as One and Two
    Game of Credit Cards
    WOW Factor
    Lose it!
  • 原文地址:https://www.cnblogs.com/qiyecao/p/10637403.html
Copyright © 2011-2022 走看看