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 

  • 相关阅读:
    字蛛webfont 安装及使用方法
    二级菜单被banner遮住的解决方法
    空a标签在IE下无效之解决方法
    wamp新建虚拟目录无法运行的解决方法
    js中this关键字用法详解
    css3新特性
    css手册中各种符号的意思
    gradient 渐变
    ie6-ie8中不支持opacity透明度的解决方法
    mysql给定一个随机数
  • 原文地址:https://www.cnblogs.com/qiyecao/p/10637403.html
Copyright © 2011-2022 走看看