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();
        }
    }

則可利用該窗體控制全局皮膚風格:

可根據需要將皮膚主題保存到配置文件中。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM