使用DevExpress改变WinForm皮肤(VS)
基于步入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)的更多相关文章
- 基于DevExpress的Winform程序安装包的制作
在我们做系统开发的时候,都会面临一个安装包制作的问题,如何把我们做好的系统,通过安装包工具整合成一个安装包给客户进行安装.安装包的优势就是一步步安装就可以了,不用复制一大堆文件给客户,还怕缺少那个文件 ...
- 老蜗牛写采集:一个漂亮的客户端-几个C#平台下的Winform 皮肤控件
搞采集多年,避免不了搞个简单的UI来曹州,所谓人靠衣装马靠鞍,一套漂亮的皮肤会给你的程序带来高大上的感觉.有时候老板也是看心情的,好的东西总归可以避免点缺点.今天给大家介绍几个曾经研究过的WinFor ...
- WinForm皮肤 支持.NET4.0 IrisSkin4多彩皮肤演示和下载
IrisSkin4是一款.NET平台非常优秀的Winform皮肤,链接库文件仅544kb,使用方法也非常简单 IrisSkin4(IrisSkin4.dll + 73套皮肤)[下载地址] 使用方法: ...
- winform 皮肤
winform 皮肤 https://github.com/kwonganding/winform.controls
- WinForm 皮肤,自定义控件WinForm.UI
WinForm.UI https://github.com/YuanJianTing/WinForm.UI WinForm 皮肤,自定义控件 使用方式: BaseForm: public partia ...
- 总结开发中基于DevExpress的Winform界面效果
DevExpress是一家全球知名的控件开发公司, DevExpress 也特指此公司出品的控件集合或某系列控件或其中某控件.我们应用最为广泛的是基于Winform的DevExpress控件组,本篇随 ...
- DevExpress.XtraGrid winform试用分享
DevExpress.XtraGrid在winform里使用还挺麻烦,为了减少重复代码和代码复用,本人针对DevExpress.XtraGrid封装了一个Form的基类,其中涵盖了DevExpress ...
- DevExpress如何实现皮肤的添加及本地化
DevExpress.XtraBars.Helpers.SkinHelper类允许您填充现有RibbonGalleryBarItem或任意菜单(PopupMenu或BarSubItem)项目对应的De ...
- DevExpress Ribbongallerybaritem选择性皮肤重组
void InitSkinGallery() () { SkinHelper skinHelper = new SkinHelper(); RibbonControl masterRibbonCont ...
随机推荐
- Okhttp【简介】应用 示例
资源 GitHub:https://github.com/square/okhttp 官网 文档 API You'll also need Okio[https://github.c ...
- EOSS V3.0 企业运营支撑系统(基于RBAC原理的权限管理)
一:EOSS 功能介绍 其于用户,角色,权限,菜单的一套“简约实用”的权限管理系统,可在其基础之上,快速进行二次开发. 一个用户可以选择多个角色. 一个角色可以选择多个权限. 一个菜单可以有无限级子菜 ...
- ASP.NET WebServices 因 URL 意外地以“/HelloWorld”结束,请求格式无法识别。
今天在使用Asp.net做一个WebServices时通过Get方式调用方法时却出现了以下错误(仅在Get请求下,POST下正常) 在网络和MSDN上了解到WebServices默认只启用 Htt ...
- chm格式文件,win7下用c:/windows/hh.exe打开
chm格式文件,win7下用c:/windows/hh.exe打开
- Winform控件之DataGridView数据控件显示问题
近期在做同类的信息记录管理系统时遇到了DataGridView数据控件的显示问题.可能是2015年的上半年没有深入 学习C#开发的原因.这几天又一次搬出来开发,首先遇到的问题就是动态绑定数据显示的问题 ...
- Android提示版本更新的实现
一.首先,参考了以下文章<Android自动检测版本及自动升级> http://www.linuxidc.com/Linux/2011-10/45718p2.htm: 步骤: .检测当前版 ...
- 【树莓派】制作树莓派所使用的img镜像(二)
树莓派制作的镜像,需要如何使用,这里直接引用目前树莓派官方的文章,不再重复描述: 参考:http://shumeipai.nxez.com/2013/08/31/usb-image-tool.html ...
- IOS企业开发者帐号申请
想使用 XCode 的联机调试功能,必须先注册成为苹果开发者,再出99刀加入苹果 iOS 开发者计划才可以.加入苹果 iOS 开发者计划的方法 Google 一下就会找到很多链接.但是这些链接的内容都 ...
- git删除本地的资源,如何恢复?
1.$ git reset --hard HEAD 将提交重置 2.使用 $ git checkout TestTimer.java(文件名) 恢复过来了
- Ubuntu 12.04解决重启后resolv.conf清空的问题
这跟以前用RHT系的 情况是完全不一样的: 在google上搜了一下,发现这里面还真有些奥妙: 1 /etc/resolv.conf 其实是一个Link 它其实指向的是 /run/resolvconf ...