DevExpress使用心得一:换肤

转帖|使用教程|编辑:我只采一朵|2014-06-05 09:24:32.000|阅读 18648 次

概述:本文为大家介绍了使用DevExpress换肤功能的一些心得体会。

# 您正在找协同办公软件吗?点击这里站长给您推荐 #

相关链接:


最近要用到界面控件DevExpress。一句话:很好很强大,比起VS自带的winform界面,种类和花样要多了不少。然而,强力的功能带来了庞大的信息量,所以我打算通过一些小模块来和大家一起对它进行探讨和研究。今天先研究一下它的换肤功能。在控件中,其默认提供了18中风格让我们选择,如下图:

devexpress 换肤 office2010

下面就看看怎么实现让界面切换到选中风格的功能。先建立一个项目,引入一个button和一个grid如下图:

devexpress 换肤

由于在devExpress.skins.skinManager.Default.Skins中只有13中皮肤所以我们要手动添加5种,找到Designer.cs文件,添加下列代码:

 this.iPaintStyle.CategoryGuid = new System.Guid("d0173875-bf7b-4740-b252-5047db62606c");
        
            this.iPaintStyle.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
            new DevExpress.XtraBars.LinkPersistInfo(this.ipsDefault),
            new DevExpress.XtraBars.LinkPersistInfo(this.ipsWXP),
            new DevExpress.XtraBars.LinkPersistInfo(this.ipsOXP),
            new DevExpress.XtraBars.LinkPersistInfo(this.ipsO2K),
            new DevExpress.XtraBars.LinkPersistInfo(this.ipsO3)});

     private DevExpress.XtraBars.BarButtonItem ipsWXP;
        private DevExpress.XtraBars.BarButtonItem ipsOXP;
        private DevExpress.XtraBars.BarButtonItem ipsO2K;
        private DevExpress.XtraBars.BarButtonItem ipsO3;
        private DevExpress.XtraBars.BarButtonItem ipsDefault;


        this.ipsDefault = new DevExpress.XtraBars.BarButtonItem();
        this.ipsWXP = new DevExpress.XtraBars.BarButtonItem();
        this.ipsOXP = new DevExpress.XtraBars.BarButtonItem();
        this.ipsO2K = new DevExpress.XtraBars.BarButtonItem();
        this.ipsO3 = new DevExpress.XtraBars.BarButtonItem();


            // 
            // ipsDefault
            // 
            this.ipsDefault.Caption = "Default";
            this.ipsDefault.CategoryGuid = new         System.Guid("d0173875-    bf7b-4740-b252-5047db62606c");
            this.ipsDefault.Description = "Default";
            this.ipsDefault.Id = 15;
            this.ipsDefault.Name = "ipsDefault";
            this.ipsDefault.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.ips_ItemClick);
            // 
            // ipsWXP
            // 
            this.ipsWXP.Caption = "Windows XP";
            this.ipsWXP.CategoryGuid = new System.Guid("d0173875-bf7b-4740-b252-5047db62606c");
            this.ipsWXP.Description = "WindowsXP";
            this.ipsWXP.Id = 11;
            this.ipsWXP.ImageIndex = 5;
            this.ipsWXP.Name = "ipsWXP";
            this.ipsWXP.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.ips_ItemClick);
            // 
            // ipsOXP
            // 
            this.ipsOXP.Caption = "Office XP";
            this.ipsOXP.CategoryGuid = new System.Guid("d0173875-bf7b-4740-b252-5047db62606c");
            this.ipsOXP.Description = "OfficeXP";
            this.ipsOXP.Id = 12;
            this.ipsOXP.ImageIndex = 3;
            this.ipsOXP.Name = "ipsOXP";
            this.ipsOXP.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.ips_ItemClick);
            // 
            // ipsO2K
            // 
            this.ipsO2K.Caption = "Office 2000";
            this.ipsO2K.CategoryGuid = new System.Guid("d0173875-bf7b-4740-b252-5047db62606c");
            this.ipsO2K.Description = "Office2000";
            this.ipsO2K.Id = 13;
            this.ipsO2K.ImageIndex = 4;
            this.ipsO2K.Name = "ipsO2K";
            this.ipsO2K.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.ips_ItemClick);
            // 
            // ipsO3
            // 
            this.ipsO3.Caption = "Office 2003";
            this.ipsO3.CategoryGuid = new System.Guid("d0173875-bf7b-4740-b252-5047db62606c");
            this.ipsO3.Description = "Office2003";
            this.ipsO3.Id = 14;
            this.ipsO3.ImageIndex = 6;
            this.ipsO3.Name = "ipsO3";
            this.ipsO3.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.ips_ItemClick);            

然后将其添加到barManager的项中。

this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] {
            this.barSubItem1,
            this.barSubItem2,
            this.ipsWXP,
            this.ipsOXP,
            this.ipsO2K,
            this.ipsO3,
            this.ipsDefault,
            this.iPaintStyle});

然后添加这几种风格的点击事件。

private void ips_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barManager1.GetController().PaintStyleName = e.Item.Description;
            InitPaintStyle(e.Item);
            barManager1.GetController().ResetStyleDefaults();
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetDefaultStyle();
        }

然后将皮肤初始化并为其注册选择事件。

private void iPaintStyleStyle_Init()
        {
            BarItem item = null;
            for (int i = 0; i < barManager1.Items.Count; i++)
            {
                if (barManager1.Items[i].Description == barManager1.GetController().PaintStyleName)
                    item = barManager1.Items[i];
            }
            InitPaintStyle(item);
        }

        private void InitPaintStyle(BarItem item)
        {
            if (item == null)
            {
                iPaintStyle.ImageIndex = item.ImageIndex;
                iPaintStyle.Caption = item.Caption;
                iPaintStyle.Hint = item.Description;
            }
        }

        void InitSkins()
        {
            barManager1.ForceInitialize();
            foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins)
            {
                BarButtonItem item = new BarButtonItem(barManager1, skinMask + cnt.SkinName);
                iPaintStyle.AddItem(item);
                item.ItemClick += new ItemClickEventHandler(OnSkinClick);

            }
        }

        void OnSkinClick(Object sender, ItemClickEventArgs e)
        {
            string skinName = e.Item.Caption.Replace(skinMask, "");
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skinName);
            barManager1.GetController().PaintStyleName = "Skin";
            iPaintStyle.Caption = iPaintStyle.Hint = e.Item.Caption;
            iPaintStyle.Hint = iPaintStyle.Caption;
            iPaintStyle.ImageIndex = -1;
        }

大功告成:初始化winform的时候调用下面两个方法就可以进行换肤了。

 iPaintStyleStyle_Init();
            InitSkins();

效果如下:

devexpress 换肤

 

devexpress 换肤

 

 

devexpress 换肤

 

转自http://www.cnblogs.com/xuekai-to-sharp/p/3759675.html

>>DevExpress 2014.1下载

慧都学院2017全新DevExpress线下研修班火热报名中!




标签:DevExpress皮肤

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果

文章转载自:慧都控件

登录 慧都网发表评论


暂无评论...

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
title
相关厂商
相关产品
DevExpress Universal Subscription

行业领先的界面控件开发包,帮助企业构建卓越应用!

DevExpress WPF Subscription

高效MVVM开发模式,WPF界面解决方案首选工具,帮助企业实现酷炫动效界面。

DevExpress Silverlight Controls

高性价比高实用性的Silverlight用户界面控件套包,拥有大量的示例和帮助文档,开发者能够快速上手!

DevExpress WinForms Subscription

为Windows Forms平台创建具有影响力的业务解决方案,高性价比WinForms界面控件套包。

DevExpress DXperience Subscription

高性价比的企业级.NET用户界面套包,助力企业创建卓越应用!

DevExpress ASP.NET Controls

多款重量级ASP.NET用户界面组件套包,让您快速开发出完美、强大的应用程序!

DevExpress Windows 8 XAML Controls

Windows 8 XAML创建基于XAML的高度交互的应用程序,这些应用程序强调用户当下的需求,并且创建下一代可触屏的解决方案。

在线
客服
在线
QQ
咨询
电话
173-8239-2642
购物车 反馈 返回
顶部
在线客服系统
live chat