DevExpress控件的主题不仅多种多样,而且非常美观大方,以对完美观念不强的我们绝对是个惊喜,当然了,对于我们的用户也是一个福音,因为他们再对不用抱怨我人软件界面是如何的粗造了。
l 如何打造美丽的界面?
l 如何快速的更换漂亮的主题?
l 如何快速的使用类似于Offcie2007的操作面板?
......
本节课程将一一解答,带您进入美轮美奂的DevExpress世界!
当我们打开或新建一个“Windows程序”,系统默认会有一个From,名称为From1。请注意,此时的”Form1”继承的是Windows 自带的Form,即”System.Windows.Forms”。而这个Form是不会应用DevExpress的主题样式的。
那么我们怎么样才可以让Form应用这些样式呢?
当我们安装完DevExpress控件包之后,在添加新项窗口中我们会看到多出的几项:如图:
分别是:DevExpress Form v9.1、DevExpress RibbomForm v9.1和DevExpressUsercontrol v9.1,其中“v9.1”是版本号。
当我们在新建“Form”时,选择DevExpress Form为模板,就可以应用DevExpress的漂亮主题了。此时,From继承的是“DevExpress.XtraEditors.XtraForm”。默认情况下,系统主题有:
Caramel
Money Twins
Lilian
The Asphalt World
iMaginary
Black
Blue
这几种主题,具体效果自己写个例子看看吧! 但DevExpress提供了更多的主题, 我们如果应用的话,必须添加以下引用 :
DevExpress..OfficeSkins.v9.1;
DevExpress.BonusSkins.v9.1;
除此之外,必须在“Program.cs”文件在添加如下代码:
DevExpress.UserSkins.OfficeSkins.Register();
DevExpress.UserSkins.BonusSkins.Register();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
if ( ! DevExpress.Skins.SkinManager.AllowFormSkins)
DevExpress.Skins.SkinManager.EnableFormSkins();
Application.Run( new frmMain());
Office 2007 Blue
Office 2007 Black
Office 2007 Silver
Office 2007 Green
Office 2007 Pink
“BonusSkins”的主题有:
Coffee
Liquid Sky
London Liquid Sky
Glass Oceans
Stardust
Xmas 2008 Blue
Valentine
McSkin
Summer 2008
Pumpkin
Dark Side
Springtime
通过“foreach(SkinContainer cnt in SkinManager.Default.Skins){}”可以获取现有所有遥主题名称,可以把获取的主题添另到菜单上,让用户选择自己喜爱的主题样式。
通过对“DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName”设置主题名称,就可以轻松的更换主题,是不是很方便?!
下面就写一个例子,展示一下它们漂亮的“皮肤”吧!
Microsoft Office 2007窗口的操作面板非常漂亮,值得让人欣喜的是DevExpress里不仅有“RibbonControl”这样的控件,还有现成的Form 模板直接使用,添加一个:
添加新项—选项“DevExpress RibbomForm v9.1”,OK。这么简单!!!
以下是主要代码及运行效果:
public frmMain()
{
InitializeComponent();
BarSubItem skinBar = new BarSubItem(barManager1, " Look and Feel " );
this .mainMenuBar.AddItem(skinBar);
string bonusSkinNames = " ;Coffee;Liquid Sky;London Liquid Sky;Glass Oceans;Stardust;Xmas 2008 Blue;Valentine;McSkin;Summer 2008;Pumpkin;Dark Side;Springtime " ;
BarSubItem BonusSkins = new BarSubItem(barManager1, " Bonus Skins " );
BarSubItem OfficeSkins = new BarSubItem(barManager1, " Office Skins " );
BarSubItem Skins = new BarSubItem(barManager1, " Skins " );
foreach (SkinContainer cnt in SkinManager.Default.Skins)
{
BarButtonItem subMenu = new BarButtonItem(barManager1, cnt.SkinName);
subMenu.ItemClick += new ItemClickEventHandler(subMenu_ItemClick);
if (cnt.SkinName.IndexOf( " Office " ) > - 1 )
{
OfficeSkins.AddItem(subMenu);
}
else if (bonusSkinNames.IndexOf( string .Format( " ;{0} " , cnt.SkinName)) > - 1 )
{
BonusSkins.AddItem(subMenu);
}
else
{
Skins.AddItem(subMenu);
}
}
string [] OtherSkins = new string [] { " Default " , " Flat " , " Ultra Flat " , " Style3D " , " Office2003 " };
for ( int i = 0 ; i < OtherSkins.Length; i ++ )
{
BarButtonItem subMenu = new BarButtonItem(barManager1, OtherSkins[i]);
subMenu.ItemClick += new ItemClickEventHandler(subMenu_ItemClick);
skinBar.AddItem(subMenu);
}
skinBar.AddItem(Skins);
skinBar.AddItem(OfficeSkins);
skinBar.AddItem(BonusSkins);
}
void subMenu_ItemClick( object sender, ItemClickEventArgs e)
{
switch (e.Item.Caption)
{
case " Style3D " :
// DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = LookAndFeelStyle.Style3D;
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetStyle3D();
break ;
case " Office2003 " :
// DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = LookAndFeelStyle.Office2003;
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetOffice2003Style();
break ;
case " Ultra Flat " :
// DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = LookAndFeelStyle.UltraFlat;
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetUltraFlatStyle();
break ;
case " Flat " :
// DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = LookAndFeelStyle.Flat;
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetFlatStyle();
break ;
default :
// DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = LookAndFeelStyle.Skin;
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetDefaultStyle();
break ;
}
DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = e.Item.Caption;
//
}