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
andUserLookAndFeel.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
- Form1.cs (VB: Form1.vb)
- Program.cs (VB: Program.vb)
See Also
- SVG Skins and Palettes – FAQ
- DevExpress WinForms Cheat Sheet - Appearances and Skins
- Application Settings Overview
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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";
}
}
}
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());
}
}
}