日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

遍历WinForm窗体 根据语言类型设置其控件Text显示

發布時間:2025/3/15 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 遍历WinForm窗体 根据语言类型设置其控件Text显示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

示例內容:

Form1 中 有一個Label1
??? 中文時顯示 " 姓名:"
??? 英文時顯示 " Name: "
??? 開發時 默認顯示為 " Name: "
??? 有一個彈出的提示信息MessageBox.Show

中文時語言文件的內容:
Name:===姓名:
Home Address: ===家庭地址:


1、語言文件讀取并設置控件Text顯示的 處理類

?

代碼 using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Collections;
using?System.IO;
using?System.Windows.Forms;

namespace?LngTxtReader
{
????
public?class?LngTxtReader
????{

????????
public?Hashtable?SetTextByLng(System.Windows.Forms.Form?winform,?string?strLngTxtPath)
????????{
????????????Hashtable?ht?
=?new?Hashtable();
????????????
if?(winform?==?null)
????????????{
????????????????
return?ht;
????????????}

????????????
if?(File.Exists(strLngTxtPath))
????????????{
????????????????
????????????????
string?strlineContent;
????????????????
int?iIndex;

????????????????System.IO.StreamReader?file?
=?new?System.IO.StreamReader(strLngTxtPath);
????????????????
????????????????
while?((strlineContent?=?file.ReadLine())?!=?null)
????????????????{
????????????????????iIndex?
=?strlineContent.IndexOf("===");//語言文件的字串?以===區隔?key?和?value
????????????????????ht.Add(strlineContent.Substring(0,?iIndex).Trim(),?strlineContent.Substring(iIndex?+?3,?strlineContent.Length?-?iIndex?-?3).Trim());
????????????????}

????????????????
if?(ht.Count?>?0)
????????????????{
????????????????????winform.Text?
=?GetMsgByLng(?winform.Text,?ht);
????????????????????fn_FindControl(winform.Controls,?ht);
????????????????}
????????????}

????????????
return?ht;
????????}

????????
private?void?fn_FindControl(Control.ControlCollection?ctls,Hashtable?ht)
????????{
????????????
foreach?(Control?ctl?in?ctls)
????????????{
????????????????
if?(ht.Contains(ctl.Text.Trim()))
????????????????{
????????????????????ctl.Text?
=?ht[ctl.Text.Trim()].ToString();
????????????????}
????????????????
if?(ctl.HasChildren)
????????????????{
????????????????????fn_FindControl(ctl.Controls,ht);
????????????????}
????????????}
????????}

????????
public?string?GetMsgByLng(string?strMsg,?Hashtable?ht)
????????{
????????????
string?strMsgWithLng?=?strMsg.Trim();
????????????
if?(ht.Contains(strMsg.Trim()))
????????????{
????????????????strMsgWithLng?
=?ht[strMsg.Trim()].ToString();
????????????}
????????????
return?strMsgWithLng;
????????}
????}
???
}

?

2、調用上述處理

代碼 ???public?Form1()
???{
????????InitializeComponent();
????????
#region?語言顯示
????????
string?currDirPath?=?new?System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory.FullName;
????????
string?strFilePath?=?currDirPath?+?"\\PassChcek_Lng1033.txt";
????????LngTxtReader.LngTxtReader?lngReader?
=?LngTxtReader.LngTxtReader();
????????ht?
=?lngReader.SetTextByLng(this,strFilePath);
????????
#endregion
????}

????
private?void?button1_Click(object?sender,?EventArgs?e)
????{
????????MessageBox.Show(
new?Xys.Comm.LngTxtReader.LngTxtReader().GetMsgByLng("Hello?world",ht));
????}

?

?

?

?

轉載于:https://www.cnblogs.com/freeliver54/archive/2010/11/23/1885333.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的遍历WinForm窗体 根据语言类型设置其控件Text显示的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。