DevExpress 换肤

1.首先添加DevExpress.OfficeSkins和DevExpress.BonusSkins 两个引用。

 在Main()函数之前进行皮肤注册:

    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            DevExpress.UserSkins.BonusSkins.Register();//皮肤注册
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();//激活窗体皮肤,否则窗体还是操作系统默认主题风格
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = "Blue";          
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new XtraForm1());
        }
    }

  

2.添加一个父窗体,加一个全局静态DefaultLookAndFeel 成员控制皮肤,其他所有的窗体都继承该父窗体。

     public partial class frmBase : DevExpress.XtraEditors.XtraForm
    {

        private static DefaultLookAndFeel gLobalDefaultLookAndFeel = new DefaultLookAndFeel();

        public static DefaultLookAndFeel GLobalDefaultLookAndFeel
        {
            get { return frmBase.gLobalDefaultLookAndFeel; }
            set { frmBase.gLobalDefaultLookAndFeel = value; }
        }

        public frmBase()
        {
            InitializeComponent();
        }
    }

3.添加一个控制皮肤的窗体frmSkin:

    public partial class frmSkin : DevExpress.XtraEditors.XtraForm
    {
        public frmSkin()
        {
            InitializeComponent();
        }

        private void frmSkin_Load(object sender, EventArgs e)
        {
            foreach (DevExpress.Skins.SkinContainer skinc in DevExpress.Skins.SkinManager.Default.Skins)
            {
                cboSkins.Properties.Items.Add(skinc.SkinName);
            }
        }

        private void cboSkins_SelectedIndexChanged(object sender, EventArgs e)
        {
            frmBase.GLobalDefaultLookAndFeel.LookAndFeel.SkinName = cboSkins.Text;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

则可利用该窗体控制全局皮肤风格:

可根据需要将皮肤主题保存到配置文件中。

posted @ 2012-07-23 15:51  霜天雪舞  阅读(2859)  评论(3编辑  收藏  举报