[C#] DevExpress插件中的GridView控件界面风格保存与还原 →→→→→进入此内容的聊天室

来自 , 2020-07-14, 写在 C#, 查看 134 次.
URL http://www.code666.cn/view/7e837225
  1. //DevExpress.XtraGrid.Views.Grid.GridView控件风格保存与还原
  2. //关键函数:①SaveLayoutToXml (string xmlFile);②RestoreLayoutFromXml (string xmlFile)
  3.  
  4.         /// <summary>
  5.         /// 获取当前目录(该进程从中启动的目录)的完全限定目录
  6.         /// </summary>
  7.         private string m_BathPath = System.Environment.CurrentDirectory;
  8.        
  9.         //窗体加载事件:先保存原始风格,再加载自定义风格
  10.         private void Form1_Load(object sender, EventArgs e)
  11.         {
  12.             this.SaveFormStyleXML(true);//保存原始风格
  13.             this.LoadFormStyleXML(false);//加载自定义风格
  14.         }
  15.  
  16.         //窗体关闭前事件:保存自定义风格
  17.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  18.         {
  19.             this.SaveFormStyleXML(false);//保存自定义风格
  20.         }
  21.        
  22.         //Btn保存风格
  23.         private void btnSaveStyle_Click(object sender, EventArgs e)
  24.         {
  25.             this.SaveFormStyleXML(false);//保存自定义风格
  26.         }
  27.  
  28.         //Btn还原风格
  29.         private void btnRestoreStyle_Click(object sender, EventArgs e)
  30.         {
  31.             this.LoadFormStyleXML(true);//加载原始风格
  32.         }
  33.        
  34.         /// <summary>
  35.         /// 保存界面风格
  36.         /// </summary>
  37.         private void SaveFormStyleXML(bool p_IsOriginal)
  38.         {
  39.             //XML文件保存目录
  40.             string dirPath = m_BathPath + "\\config\\";
  41.             //检查XML保存目录是否存在,若不存在则新建
  42.             if (!System.IO.Directory.Exists(dirPath))
  43.             {
  44.                 System.IO.Directory.CreateDirectory(dirPath);
  45.             }
  46.             //若为原始风格,需加前缀Original_
  47.             if (p_IsOriginal)
  48.             {
  49.                 dirPath += "Original_";
  50.             }
  51.             //保存GridView显示风格
  52.             string fullPath = dirPath + "gdvStyle.xml";
  53.             this.gridView1.SaveLayoutToXml(fullPath);
  54.         }
  55.        
  56.         /// <summary>
  57.         /// 加载界面风格
  58.         /// </summary>
  59.         private void LoadFormStyleXML(bool p_IsOriginal)
  60.         {
  61.             //XML文件保存目录
  62.             string dirPath = m_BathPath + "\\config\\";
  63.             //若为原始风格,需加前缀Original_
  64.             if (p_IsOriginal)
  65.             {
  66.                 dirPath += "Original_";
  67.             }
  68.             //加载GridView显示风格
  69.             string fullPath = dirPath + "gdvStyle.xml";
  70.             if (System.IO.File.Exists(path_QueryYY))
  71.             {
  72.                 this.gridView1.RestoreLayoutFromXml(fullPath);
  73.             }
  74.         }

回复 "DevExpress插件中的GridView控件界面风格保存与还原"

这儿你可以回复上面这条便签

captcha