Example T581395
Visible to All Users

WinForms Skins - Save/restore the active skin and palette between application sessions

The Windows Forms Application Settings feature allows you to create, store, and maintain user preferences on client computers. You can use this feature to save the active skin and palette and restore these settings when your application restarts.

  • Double-click the Settings.settings file in the Visual Studio Solution Explorer.
  • Create two entries of the String type.
  • Set the scope of both entries to "User".
  • When your application is about to close, save values of UserLookAndFeel.Default.SkinName and UserLookAndFeel.Default.ActiveSvgPaletteName properties to Application Settings.
  • When your application starts, read saved settings and pass them to the UserLookAndFeel.SetSkinStyle method as parameters.

Files to Review

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

DXApplication1/Form1.cs(vb)
C#
using DevExpress.LookAndFeel; using DevExpress.Skins; using DevExpress.Utils.Svg; using DXApplication1.Properties; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace DXApplication1 { public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm { public Form1() { InitializeComponent(); this.FormClosing += Form1_FormClosing; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { SavePalette(); } private void ShowSwatchPicker(Form owner) { using(var dialog = new DevExpress.Customization.SvgSkinPaletteSelector(owner)) { dialog.ShowDialog(); SavePalette(); } } private void SavePalette() { var settings = Properties.Settings.Default; settings.SkinName = UserLookAndFeel.Default.SkinName; settings.Palette = UserLookAndFeel.Default.ActiveSvgPaletteName; settings.CompactMode = UserLookAndFeel.Default.CompactUIModeForced; settings.Save(); } protected override void OnShown(EventArgs e) { base.OnShown(e); RestorePalette(); ShowSettings(); } private void RestorePalette() { var settings = Properties.Settings.Default; if (!string.IsNullOrEmpty(settings.SkinName)) { if (settings.CompactMode) UserLookAndFeel.ForceCompactUIMode(true, false); if (!string.IsNullOrEmpty(settings.Palette)) UserLookAndFeel.Default.SetSkinStyle(settings.SkinName, settings.Palette); else UserLookAndFeel.Default.SetSkinStyle(settings.SkinName); } } private void ShowSettings() { labelControl1.Text = Settings.Default.SkinName; labelControl4.Text = Settings.Default.Palette != String.Empty ? Settings.Default.Palette : "n/a (default palette or raster skin)"; labelControl6.Text = Settings.Default.CompactMode ? "Yes" : "No"; } } }
DXApplication1/Program.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using DevExpress.UserSkins; using DevExpress.Skins; namespace DXApplication1 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); BonusSkins.Register(); SkinManager.EnableFormSkins(); Application.Run(new Form1()); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.