windowsforms-117177-build-an-application-application-skins-add-and-customize-the-toolbar-and-menu-skin-selector.md
You can add skin selectors to a toolbar (BarManager) and Ribbon Control to allow users to choose skins at runtime.
At design time, click the [Add] button in the toolbar, and select a skin selector from the Skin Item sub-menu.
The following skin selectors are available:
Skin Menu (SkinBarSubItem) — Displays skin names as a menu.
Skin List (SkinDropDownButtonItem) — Displays skin names as a scrollable list with a built-in search box to locate skins by name.
Skin Palette List (SkinPaletteDropDownButtonItem) — Displays palettes for the currently selected vector skin.
You can modify skin selectors in code. To do this, use a skin selector’s BarCustomContainerItem.ItemLinks collection.
When you create skin selectors (SkinBarSubItem, SkinDropDownButtonItem, SkinPaletteDropDownButtonItem, SkinRibbonGalleryBarItem, and SkinPaletteRibbonGalleryBarItem) and add them to a toolbar or Ribbon control in code, ensure that you call the skin selector’s Initialize method.
SkinBarSubItem skinBarSubItem1 = new SkinBarSubItem();
barManager1.Items.Add(skinBarSubItem1);
bar1.ItemLinks.Add(skinBarSubItem1);
skinBarSubItem1.Initialize();
Dim skinBarSubItem1 As New SkinBarSubItem()
BarManager1.Items.Add(skinBarSubItem1)
Bar1.ItemLinks.Add(skinBarSubItem1)
skinBarSubItem1.Initialize()
Tip
Read the following help topic for information on how to display pre-designed Ribbon UI commands that correspond to advanced skin settings: Ribbon Skin Selectors.
You can hide individual items in a skin selector as follows:
Create a string array of skin names to exclude. You can use the full name (for example, “Office 2016 Colorful”) or partial name (for example, “2007”).
Create a custom method (HideSkins) that iterates through the skin selector’s items, and remove skins that match values in the array.
Call the HideSkins method from the Load event handler.
Iterate through the skin selector’s ItemLinks collection to change an item caption or glyph.
void ucBar_Load(object sender, EventArgs e) {
RenameSkins();
}
private void RenameSkins() {
for(var i = 0; i < skinBarSubItem1.ItemLinks.Count; i++) {
if(skinBarSubItem1.ItemLinks[i].Caption == "DevExpress Style") {
BarButtonItem parentItem = (BarButtonItem)skinBarSubItem1.ItemLinks[i].Item;
parentItem.Caption = "Default Skin";
parentItem.ImageUri.Uri = "Apply";
}
}
}
Private Sub ucBar_Load(ByVal sender As Object, ByVal e As EventArgs)
RenameSkins()
End Sub
Private Sub RenameSkins()
For i = 0 To skinBarSubItem1.ItemLinks.Count - 1
If skinBarSubItem1.ItemLinks(i).Caption = "DevExpress Style" Then
Dim parentItem As BarButtonItem = CType(skinBarSubItem1.ItemLinks(i).Item, BarButtonItem)
parentItem.Caption = "Default Skin"
parentItem.ImageUri.Uri = "Apply"
End If
Next i
End Sub
The figure below shows the result:
You can also use a Localizer object to rename skin items. See the following article to learn more: Localize Skin Selectors.