基于步入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. 2.6 《硬啃设计模式》第8章 复制不是很难 - 原型模式(Prototype Pattern)

    案例: 某即时战略游戏,你训练出来各种很强的战士. 为了增加游戏的可玩性,增加了一种复制魔法.实施该魔法,可以复制任意的战士. 你会怎样考虑这个设计? 在继续阅读之前,请先认真思考并写出你的设计,这样 ...

  2. Word Break leetcode java

    题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...

  3. Nginx配置文件(nginx.conf)配置具体解释

    欢迎扫码增加Java高知群交流 Nginx的配置文件nginx.conf配置具体解释例如以下:   user nginx nginx ; Nginx用户及组:用户 组. window下不指定   wo ...

  4. RS错误RSV-VAL-0032之项目未在布局中引用的3种解决办法

    如下图所示,我用RS新建了一个空白页面,拖入了一个列表,给该列表新建了一个条件样式 条件样式如下所示,表达式来自查询1 运行,报错如下图所示 原因就是条件样式使用到了查询1中的数据项1但是数据项1在报 ...

  5. 如何利用Framework模型生成IQD文件

    很多Cognos的新手在接触Transform建模的时候对于iqd文件都有一种朦胧的感觉,当然也不必去死记硬别它的格式,下面我们就来说一下如何用Framework工具来生成iqd文件. 1:打开fra ...

  6. (转)NGUI系列教程七(序列帧动画UITexture 和 UIsprit)

    NGUI系列教程七(序列帧动画)   今天我给大家讲一下如何使用NGUI做序列帧动画.本节主要包括两方面内容,分别是使用UIspirit和使用UITexture 做序列帧动画.废话不说了,下面开始.还 ...

  7. [Algorithm] Largest sum of non-adjacent numbers

    Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Num ...

  8. Android 之 AndroidManifest.xml 详解(二)

    [10]<activity> Activity活动组件(即界面控制器组件)的声明标签,Android应用中的每一个Activity都必须在AndroidManifest.xml配置文件中声 ...

  9. json的工具按照键进行排序

    浏览器中,所有涉及json的工具会按照键进行排序,这个与实际的查询的数组的顺序有出入,见下图:

  10. mac 连接windows 共享内容

    mac 连接windows 共享内容 一:场景 在win7上下载了一个5G左右的系统文件,想弄到mac上,本打算用使用U盘,把文件从win7copy到mac电脑上: 可是U盘的分区是fat的,大于4G ...