• 00
  • :
  • 00
  • :
  • 00

DEV界面皮肤

1.添加一个

image

 

2.添加引用:

image

 

 

3.添加一个SkinTools类

public class SkinTools
    {
        /// <summary>
        /// 在Program中调用
        /// </summary>
        public static void InitOtherSkin()
        {
            //皮肤
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.Skins.SkinManager.EnableMdiFormSkins();
        }


        string defaultSkinName;//皮肤

        string XMLPath = Application.StartupPath + @"\Config\SystemInfo.xml";//保存有皮肤信息的XML文件
        DevExpress.XtraBars.RibbonGalleryBarItem RgbiSkin;


        public static void InitSkinGallery(DevExpress.XtraBars.RibbonGalleryBarItem rgbiSkin)
        {
            new SkinTools(rgbiSkin);
        }

        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="rgbiSkin"></param>
        SkinTools(DevExpress.XtraBars.RibbonGalleryBarItem rgbiSkin)
        {
            InitOtherSkin();//添加皮肤
            InitialSkin(rgbiSkin);

        }

        /// <summary>
        /// 加载皮肤到控件
        /// </summary>
        /// <param name="RGBISkin"></param>
        void InitialSkin(DevExpress.XtraBars.RibbonGalleryBarItem RGBISkin)
        {
            RgbiSkin = RGBISkin;
            SkinHelper.InitSkinGallery(RgbiSkin);
            XMLCheckFile(XMLPath);//检查文件
            GetXmlSkin();//获取xml主题
            UserLookAndFeel.Default.SetSkinStyle(defaultSkinName);//设置主题样式
            RgbiSkin.Caption = "主题:" + defaultSkinName;

            RgbiSkin.GalleryItemClick += rgbiSkin_GalleryItemClick;
        }

        /// <summary>
        /// 皮肤改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void rgbiSkin_GalleryItemClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
        {
            try
            {

                string name = string.Empty;
                string caption = string.Empty;

                if (RgbiSkin.Gallery == null) return;
                caption = RgbiSkin.Gallery.GetCheckedItems()[0].Caption;//主题的描述
                caption = caption.Replace("主题:", "");
                //name = bsiPaintStyle.Manager.PressedLink.Item.Tag.ToString();//主题的名称
                RgbiSkin.Caption = "主题:" + caption;

                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load("SkinInfo.xml");
                System.Xml.XmlNodeList nodelist = doc.SelectSingleNode("SetSkin").ChildNodes;
                foreach (System.Xml.XmlNode node in nodelist)
                {
                    System.Xml.XmlElement xe = (System.Xml.XmlElement)node;//将子节点类型转换为XmlElement类型 
                    if (xe.Name == "Skinstring")
                    {
                        xe.InnerText = caption;
                    }
                }

                doc.Save(XMLPath);
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// 获得皮肤
        /// </summary>
        void GetXmlSkin()
        {
            try
            {
                XmlDocument mydoc = new XmlDocument();
                mydoc.Load(XMLPath);
                System.Xml.XmlNode ressNode = mydoc.SelectSingleNode("SetSkin");
                defaultSkinName = ressNode.SelectSingleNode("Skinstring").InnerText;

            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }



        public void XMLCheckFile(string filename)
        {
            try
            {
                if (System.IO.File.Exists("SkinInfo.xml") == false)
                {
                    //XtraMessageBox.Show("不存在XML");
                    XMLCreate(filename);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        /// <summary>
        /// 创建XML文件
        /// </summary>
        /// <param name="filename">要将文档保存到其中的文件位置</param>
        public void XMLCreate(string filename)
        {
            XmlDocument doc = new XmlDocument();
            //建立xml定义声明
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.AppendChild(dec);

            //创建根节点
            XmlElement root = doc.CreateElement("SetSkin");
            XmlElement rootone = doc.CreateElement("Skinstring");//皮肤

            //Application.StartupPath + @"\Config\SystemInfo.xml"
            //将one,two,插入到root节点下
            doc.AppendChild(root);
            root.AppendChild(rootone);
            doc.Save(filename);
        }
    }
4.窗体Load事件中添加
SkinTools.InitSkinGallery(ribbonGalleryBarItem1);//加载皮肤

5.启动目录下的XML文件SkinInfo.xml

<?xml version="1.0" encoding="utf-8"?>
<SetSkin>
  <Skinstring>Summer</Skinstring>
</SetSkin>
posted @ 2014-12-02 16:56  Garson_Zhang  阅读(1796)  评论(0编辑  收藏  举报