[c#]代码库
//DevExpress.XtraGrid.Views.Grid.GridView控件风格保存与还原
//关键函数:①SaveLayoutToXml (string xmlFile);②RestoreLayoutFromXml (string xmlFile)
/// <summary>
/// 获取当前目录(该进程从中启动的目录)的完全限定目录
/// </summary>
private string m_BathPath = System.Environment.CurrentDirectory;
//窗体加载事件:先保存原始风格,再加载自定义风格
private void Form1_Load(object sender, EventArgs e)
{
this.SaveFormStyleXML(true);//保存原始风格
this.LoadFormStyleXML(false);//加载自定义风格
}
//窗体关闭前事件:保存自定义风格
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.SaveFormStyleXML(false);//保存自定义风格
}
//Btn保存风格
private void btnSaveStyle_Click(object sender, EventArgs e)
{
this.SaveFormStyleXML(false);//保存自定义风格
}
//Btn还原风格
private void btnRestoreStyle_Click(object sender, EventArgs e)
{
this.LoadFormStyleXML(true);//加载原始风格
}
/// <summary>
/// 保存界面风格
/// </summary>
private void SaveFormStyleXML(bool p_IsOriginal)
{
//XML文件保存目录
string dirPath = m_BathPath + "\\config\\";
//检查XML保存目录是否存在,若不存在则新建
if (!System.IO.Directory.Exists(dirPath))
{
System.IO.Directory.CreateDirectory(dirPath);
}
//若为原始风格,需加前缀Original_
if (p_IsOriginal)
{
dirPath += "Original_";
}
//保存GridView显示风格
string fullPath = dirPath + "gdvStyle.xml";
this.gridView1.SaveLayoutToXml(fullPath);
}
/// <summary>
/// 加载界面风格
/// </summary>
private void LoadFormStyleXML(bool p_IsOriginal)
{
//XML文件保存目录
string dirPath = m_BathPath + "\\config\\";
//若为原始风格,需加前缀Original_
if (p_IsOriginal)
{
dirPath += "Original_";
}
//加载GridView显示风格
string fullPath = dirPath + "gdvStyle.xml";
if (System.IO.File.Exists(path_QueryYY))
{
this.gridView1.RestoreLayoutFromXml(fullPath);
}
}
by: 发表于:2018-01-24 09:45:17 顶(0) | 踩(0) 回复
??
回复评论