zoukankan      html  css  js  c++  java
  • 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 + @"ConfigSystemInfo.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 + @"ConfigSystemInfo.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>
    慎于行,敏于思!GGGGGG
  • 相关阅读:
    Day22:异常处理、socke基于TCP协议编程
    Day21:面向对象的软件开发、反射、对象的内置方法
    Day20:绑定方法与非绑定办法、多态和多态性
    Day19:继承实现的原理、子类中调用父类的方法、封装
    Day18:类的抽象、类的组合应用
    Day17:类的继承、派生、组合和接口
    Day16:面向对象编程——类和对象
    数据结构
    python爬虫篇之 性能相关
    scrapy-redis
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/4137935.html
Copyright © 2011-2022 走看看