基于步入DevExpress的使用(VS),进一步使用DevExpress改变WinForm皮肤,适合初学者。

提示:

1、对于DevExpress菜单中的RepositoryItemComboBox没有EditValue属性,无法直接获取选择的值,但可以在其事件中将其转化为ComboBoxEdit控件来获取。如下:

private void repositoryItemComboBox1_SelectedValueChanged(object sender, EventArgs e)
{
ComboBoxEdit riComboBox = sender as ComboBoxEdit;
string skinName = riComboBox.EditValue.ToString();
}

2、在设计界面代码如:BaseFormDesigner.cs中,手动给指定控件(RepositoryItemComboBox)添加事件,代码如下:

 this.repositoryItemComboBox1.SelectedValueChanged += new System.EventHandler(this.repositoryItemComboBox1_SelectedValueChanged);

  在对应的BaseForm.cs中实现其具体功能,代码如下:

        /// <summary>
/// 手动添加的 Combobox菜单项值改变时,触发的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void repositoryItemComboBox1_SelectedValueChanged(object sender, EventArgs e)
{
ComboBoxEdit repositoryItemComboBox = sender as ComboBoxEdit;
this.defaultLookAndFeel1.LookAndFeel.SkinName = repositoryItemComboBox.EditValue.ToString();
}

代码间关系:Program类主要注册要使用的皮肤及运行那个界面;CommonFunctions类主要实现共用的函数;BaseForm类继承自DevExpress.XtraEditors.XtraForm,主要实现一些基础共用的操作;SkinSubject类主要积累那些类共用BaseForm类的通用操作或共性(单例、简单观察者来实现);AppFormA、AppFormB类都继承自BaseForm类,共用BaseForm类特性。

具体实例代码(不含界面设计代码)如下:

 

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms; namespace TestExpressSkins
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.UserSkins.OfficeSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new BaseForm());
//Application.Run(new AppFormA());
Application.Run( AppFormA.Singlon());
}
}
}

  

CommonFunctions.cs

using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace TestExpressSkins
{
class CommonFunctions
{
#region 字段 #endregion #region 单例 private static CommonFunctions commFuncInstance = null; private CommonFunctions()
{
} public static CommonFunctions Singlon()
{
if (null == commFuncInstance)
{
commFuncInstance = new CommonFunctions();
}
return commFuncInstance;
} #endregion #region 共有方法
/// <summary>
/// 皮肤全部枚举出来放到一个ComboBoxEdit中
/// </summary>
/// <param name="comboBoxEdit"></param>
public void AddAppStyles2ComboBoxEdit(ComboBoxEdit comboBoxEdit)
{
foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
{
comboBoxEdit.Properties.Items.Add(skin.SkinName);
}
} /// <summary>
/// 皮肤全部枚举出来放到一个ComboBoxEdit中
/// </summary>
/// <param name="repositoryItemComboBox"></param>
public void AddAppStyles2RepositoryItemComboBox(RepositoryItemComboBox repositoryItemComboBox)
{
foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
{
repositoryItemComboBox.Items.Add(skin.SkinName);
}
} public void AddAppStyles2BarEditItem(BarEditItem barEditItem)
{
string editItemType = barEditItem.GetType().ToString();
switch (editItemType)
{
case "RepositoryItemComboBox":
AddAppStyles2RepositoryItemComboBox(barEditItem.Edit as RepositoryItemComboBox);
break;
case "RepositoryItem**": break;
case "RepositoryItem***": break; }
} #endregion #region 私有方法 public bool tmpFunc()
{
bool bFlag = true; return bFlag;
} #endregion
}
}

 SkinSubject.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace TestExpressSkins
{
public class SkinSubject
{
#region 字段 private List<BaseForm> forms = new List<BaseForm>(); //同一样式的对话框集合 #endregion #region 单例 private static SkinSubject subject = null; public static SkinSubject GetInstance()
{
if (subject == null) subject = new SkinSubject();
return subject;
} private SkinSubject() { } #endregion #region 共有方法
/// <summary>
/// 注册观察者
/// </summary>
/// <param name="f"></param>
public void Register(BaseForm f)
{
forms.Add(f);
} /// <summary>
/// 注销观察者
/// </summary>
/// <param name="f"></param>
public void UnRegister(BaseForm f)
{
forms.Remove(f);
} /// <summary>
/// 修改每个观察者的皮肤
/// </summary>
/// <param name="skinName"></param>
public void Notify(string skinName)
{
foreach (BaseForm f in forms)
{
f.LookAndFeelControl.LookAndFeel.SkinName = skinName;
}
} #endregion #region 私有方法 #endregion
}
}

  

BaseForm.cs

using DevExpress.LookAndFeel;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace TestExpressSkins
{
public partial class BaseForm : DevExpress.XtraEditors.XtraForm //Form
{
#region 字段 private CommonFunctions commFunc = null; #endregion #region 属性 public DefaultLookAndFeel LookAndFeelControl
{
set
{
} get
{
return this.defaultLookAndFeel1;
}
} public int tempA
{
set
{
} get
{
return 1;
}
} #endregion #region 构造函数 public BaseForm()
{
InitializeComponent();
commFunc = CommonFunctions.Singlon();
} #endregion #region 对话框或空间相关方法 private void Form1_Load(object sender, EventArgs e)
{
commFunc.AddAppStyles2ComboBoxEdit(cmbAppStyle);
commFunc.AddAppStyles2RepositoryItemComboBox(this.repositoryItemComboBox1);
} private void cmbAppStyle_SelectedIndexChanged(object sender, EventArgs e)
{
this.defaultLookAndFeel1.LookAndFeel.SkinName = cmbAppStyle.EditValue.ToString();
} /// <summary>
/// 手动添加的 Combobox菜单项值改变时,触发的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void repositoryItemComboBox1_SelectedValueChanged(object sender, EventArgs e)
{
ComboBoxEdit repositoryItemComboBox = sender as ComboBoxEdit;
this.defaultLookAndFeel1.LookAndFeel.SkinName = repositoryItemComboBox.EditValue.ToString();
} #endregion #region 私有方法 #endregion
}
}

  

AppFormA.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace TestExpressSkins
{
public partial class AppFormA : BaseForm //Form
{
#region 字段 BaseForm appFormB = null; #endregion #region 属性 public int tempA
{
set
{
} get
{
return 1;
}
} #endregion #region 单例 private static AppFormA appFormAInstance = null; #region 构造函数 private AppFormA()
{
InitializeComponent();
SkinSubject.GetInstance().Register(this);
} #endregion public static AppFormA Singlon()
{
if (null == appFormAInstance)
{
appFormAInstance = new AppFormA();
}
return appFormAInstance;
} #endregion #region 对话框或空间相关方法 private void bGo2B_Click(object sender, EventArgs e)
{
//if (null == appFormB)
//{
// appFormB = new AppFormB();
//}
appFormB = AppFormB.Singlon();
this.Hide();
appFormB.Show();
} #endregion #region 私有方法 #endregion
}
}

  

AppFormB.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace TestExpressSkins
{
public partial class AppFormB : BaseForm //Form
{
#region 字段 BaseForm appFormA = null; #endregion #region 属性 public int tempA
{
set
{
} get
{
return 1;
}
} #endregion #region 单例 private static AppFormB appFormBInstance = null; #region 构造函数 private AppFormB()
{
InitializeComponent();
SkinSubject.GetInstance().Register(this);
} #endregion public static AppFormB Singlon()
{
if (null == appFormBInstance)
{
appFormBInstance = new AppFormB();
}
return appFormBInstance;
} #endregion #region 对话框或空间相关方法 private void bGo2A_Click(object sender, EventArgs e)
{
//if (null == appFormA)
//{
// appFormA = new AppFormA();
//}
appFormA = AppFormA.Singlon();
this.Hide();
appFormA.Show();
} #endregion #region 私有方法 #endregion
}
}

  

使用DevExpress改变WinForm皮肤(VS)的更多相关文章

  1. 基于DevExpress的Winform程序安装包的制作

    在我们做系统开发的时候,都会面临一个安装包制作的问题,如何把我们做好的系统,通过安装包工具整合成一个安装包给客户进行安装.安装包的优势就是一步步安装就可以了,不用复制一大堆文件给客户,还怕缺少那个文件 ...

  2. 老蜗牛写采集:一个漂亮的客户端-几个C#平台下的Winform 皮肤控件

    搞采集多年,避免不了搞个简单的UI来曹州,所谓人靠衣装马靠鞍,一套漂亮的皮肤会给你的程序带来高大上的感觉.有时候老板也是看心情的,好的东西总归可以避免点缺点.今天给大家介绍几个曾经研究过的WinFor ...

  3. WinForm皮肤 支持.NET4.0 IrisSkin4多彩皮肤演示和下载

    IrisSkin4是一款.NET平台非常优秀的Winform皮肤,链接库文件仅544kb,使用方法也非常简单 IrisSkin4(IrisSkin4.dll + 73套皮肤)[下载地址] 使用方法: ...

  4. winform 皮肤

    winform  皮肤 https://github.com/kwonganding/winform.controls

  5. WinForm 皮肤,自定义控件WinForm.UI

    WinForm.UI https://github.com/YuanJianTing/WinForm.UI WinForm 皮肤,自定义控件 使用方式: BaseForm: public partia ...

  6. 总结开发中基于DevExpress的Winform界面效果

    DevExpress是一家全球知名的控件开发公司, DevExpress 也特指此公司出品的控件集合或某系列控件或其中某控件.我们应用最为广泛的是基于Winform的DevExpress控件组,本篇随 ...

  7. DevExpress.XtraGrid winform试用分享

    DevExpress.XtraGrid在winform里使用还挺麻烦,为了减少重复代码和代码复用,本人针对DevExpress.XtraGrid封装了一个Form的基类,其中涵盖了DevExpress ...

  8. DevExpress如何实现皮肤的添加及本地化

    DevExpress.XtraBars.Helpers.SkinHelper类允许您填充现有RibbonGalleryBarItem或任意菜单(PopupMenu或BarSubItem)项目对应的De ...

  9. DevExpress Ribbongallerybaritem选择性皮肤重组

    void InitSkinGallery() () { SkinHelper skinHelper = new SkinHelper(); RibbonControl masterRibbonCont ...

随机推荐

  1. 附 Java对象内存布局

    注意:本篇博客,主要参考自<深入理解Java虚拟机(第二版)> 1.对象在内存中存储的布局分为三块 对象头 存储对象自身的运行时数据:Mark Word(在32bit和64bit虚拟机上长 ...

  2. 如何强制使用某一大小的包去ping某个IP地址?

    测试MTU的时候用得到的, 命令如下: ping -f -l 9000 10.110.68.40 ping命令的帮助输出如下: C:\Users\administrator>ping /? Us ...

  3. Maximum Depth of Binary Tree leetcode java

    题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...

  4. 眼前一亮!十八款新潮而又独特的网站Header设计

    一个网站最重要的一个部分就是标题.这将是访问者的第一印象,设计出一个吸引眼球并且功能清晰导航还是比较容易的,但想出一个独特的header却总是困难的,这就是为什么我决定把那些对我有最影响的导航列出来了 ...

  5. Android -- 保存文件

    背景                                                                                             我们以常见 ...

  6. Discuz常见大问题-如何允许用户插入视频-如何自己在页面中插入视频

    从视频的下面分享中获取html代码 然后粘贴到你创建页面的指定位置(注意从优酷复制的视频宽度和高度可能比较小,你可以自己调整,或者占据100%) 最终的实现效果

  7. 【CSWS2014 Summer School】大数据下的游戏营销模式革新-邓大付

    大数据下的游戏营销模式革新 邓大付博士腾讯专家工程师 Bio:毕业于华中科技大学,现任腾讯IEG运营部数据中心技术副总监,负责腾讯游戏的数据挖掘相关工作,包括有用户画像,推荐系统,基础算法研究等.主要 ...

  8. AS3的反编译

    一个as3写的swf反编译,修改类库: http://www.swfwire.com/ http://www.swfwire.com/decompiler 基于此类库的swf反编译工具(air) ht ...

  9. java实现内部排序算法

    冒泡排序 public class BubbleSort{ public static int[] asc(int[] a){ int item; for (int i = 0; i < a.l ...

  10. Android 升级脚本updater-script 的函数简单介绍

    这是Android系统来执行updater-scripts中的函数介绍. 函数都是的Edify语言.当调用这些函数结束的时候.会返回数据给脚本.当然,你也能够使用这些函数的返回值来确认成功与否,比如: ...