📄 config.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
namespace SettingInterface
{
class Config
{
private XmlDocument ConFile = new XmlDocument();
private string FileName;
private XmlNode Root;
private Points pointList = new Points();
internal Points PointList
{
get { return pointList; }
set { pointList = value; }
}
public Config()
{
ReadFile("ConFile.xml");
}
public Config(string xmlfile)
{
ReadFile(xmlfile);
}
private point[] GetPoints()
{
XmlNode points = (XmlElement)ConFile.GetElementsByTagName("points").Item(0);
XmlNodeList ps = points.ChildNodes;
XmlNode p;
point[] result = new point[ps.Count];
for (int i = 0; i < ps.Count; i++)
{
string px, py;
p = ps.Item(i).FirstChild;
px = p.LastChild.Value.ToString();
p = ps.Item(i).LastChild;
py = p.LastChild.Value.ToString();
try
{
result[i] = new point(Convert.ToInt32(px), Convert.ToInt32(py),i);
}
catch (InvalidCastException ex)
{
System.Windows.Forms.MessageBox.Show("配置文件有错误!" + ex.Message);
}
}
return result;
}
private void ReadFile(string xmlfile)
{
FileName = xmlfile;
try
{
ConFile.Load(xmlfile);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("请检查您的配置文件是否正确" + ex.Message);
return;
}
Root = (XmlNode)ConFile;
pointList = new Points(GetPoints());
}
public void save()
{
XmlNode points = (XmlElement)ConFile.GetElementsByTagName("points").Item(0);
XmlNodeList pointList = points.ChildNodes;
XmlNode p;
int i = 0;
this.pointList.First();
do
{
p = (XmlNode)pointList.Item(i).FirstChild;
p.InnerText = this.pointList.Point.X.ToString();
p = pointList.Item(i).LastChild;
p.InnerText = this.pointList.Point.Y.ToString();
i++;
} while (this.pointList.Next());
this.pointList = new Points(GetPoints());
FileStream xmlFile = new FileStream(FileName, FileMode.OpenOrCreate);
ConFile.Save(xmlFile);
xmlFile.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -