在WinFrom开发中有中英文切换需求时
需要批量更改控件的显示名称
可以将控件名字和显示名称保存在xml文件中
可以将控件保存进文件,也可从文件中加载来更改显示名
牵涉xml文件的读写插入修改基本知识
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace WindowsFormsApp1
{
public class XML
{
public XmlDocument doc;
public XmlElement root;
public XmlDeclaration declare;
public string path;
public void CreatElement(string formName, string name, string txt)
{
if (doc == null)
doc = new XmlDocument();
if (doc.GetElementsByTagName("version") == null)
{
declare = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
doc.AppendChild(declare);
}
if (doc.SelectSingleNode(formName) == null)
{
root = doc.CreateElement(formName);
doc.AppendChild(root);
}
var nods = doc.SelectSingleNode(formName);
root = (XmlElement)nods;
bool bHave = Checkhave(formName, name, txt);
if (bHave)
{
//已经包含该名称
RenameControl(formName, name, txt);
return;
}
XmlElement Contollist;
Contollist = doc.CreateElement("控件");
XmlElement ctrolName = doc.CreateElement("控件名");
XmlText prize1 = doc.CreateTextNode(name);
ctrolName.AppendChild(prize1);
XmlElement txtName = doc.CreateElement("显示名");
XmlText num1 = doc.CreateTextNode(txt);
txtName.AppendChild(num1);
root.AppendChild(Contollist);
Contollist.AppendChild(ctrolName);
Contollist.AppendChild(txtName);
}
public void CreatElementByHashTb(string formName, Hashtable mtb=null)
{
foreach(DictionaryEntry de in mtb)
{
CreatElement(formName, de.Key.ToString(), de.Value.ToString(

这个博客介绍了一种在Windows Forms应用程序中实现中英文切换的方法,通过使用XML文件存储控件名称和显示名,实现了批量更改控件的显示名称。主要涉及XML文件的读写操作,以及对窗体控件的遍历和更新。
&spm=1001.2101.3001.5002&articleId=127412041&d=1&t=3&u=38d0686562fd4c7195208823bdeb5cf7)
4268

被折叠的 条评论
为什么被折叠?



