Don't confuse the PaintStyleKind property with the PaintStyleName property. The PaintStyleName property specifies the paint style used to paint the nav bar and this overrides all the look and feel settings specified by the NavBarControl's LookAndFeel property. The PaintStyleKind property specifies only the manner - kind, in which the nav bar is painted and allows the look and feel settings to be applied.
There are three kinds of paint styles: ExplorerBar, SideBar and NavigationPane. The ExplorerBar kind allows the nav bar to be painted flat, using the currently applied WindowsXP theme or Skin. If the nav bar is painted like a Side Bar, it can only be painted flat, using the Style3D style or WindowsXP theme currently applied. If it's painted like a Navigation Pane, the look and feel settings are ignored.

Example
This example shows how to create a NavBarControl in code.The NavBarControl will have two groups ('Charts' and 'Settings') with items. Item link selection is enabled by setting the LinkSelectionMode property to LinkSelectionModeType.OneInGroupAndAllowAutoSelect. To respond to a link selection, the SelectedLinkChanged event is handled.
In the OneInGroupAndAllowAutoSelect mode, each group can have a single selected link independent of other groups. When a group is activated and it has no selected link, the first link is auto-selected. At runtime, you will see that the SelectedLinkChanged event fires on group activation, while the LinkClicked event does not.
The example demonstrates two methods of assigning images to navbar items:1) explicit assignment of Image objects to items (see the 'Charts' navbar group item initialization);2) implicit assignment, using image indexes (see the 'Settings' navbar group item initialization).

Form1.cs |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraNavBar;
namespace CreateNavBar {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
NavBarControl navBar = new NavBarControl();
this.Controls.Add(navBar);
navBar.Width = 150;
navBar.Dock = DockStyle.Left;
navBar.PaintStyleKind = NavBarViewKind.NavigationPane;
NavBarGroup groupChart = new NavBarGroup("Charts");
groupChart.LargeImage = global::CreateNavBar.Properties.Resources.chart_32x32;
NavBarItem itemChartArea = new NavBarItem("Area");
itemChartArea.LargeImage = global::CreateNavBar.Properties.Resources.area_32x32;
NavBarItem itemChartBar = new NavBarItem("Bar");
itemChartBar.LargeImage = global::CreateNavBar.Properties.Resources.bar_32x32;
NavBarItem itemChartRefresh = new NavBarItem("Refresh");
itemChartRefresh.LargeImage = global::CreateNavBar.Properties.Resources.refresh_32x32;
itemChartRefresh.Enabled = false;
navBar.LargeImages = imageCollection1;
NavBarGroup groupSettings = new NavBarGroup("Settings");
groupSettings.LargeImage = global::CreateNavBar.Properties.Resources.customize_32x32;
NavBarItem itemEditSettings = new NavBarItem("Edit Settings");
itemEditSettings.LargeImageIndex = 0;
NavBarItem itemExport = new NavBarItem("Export");
itemExport.LargeImageIndex = 1;
navBar.BeginUpdate();
navBar.Groups.Add(groupChart);
groupChart.ItemLinks.Add(itemChartArea);
groupChart.ItemLinks.Add(itemChartBar);
groupChart.ItemLinks.Add(new NavBarSeparatorItem());
groupChart.ItemLinks.Add(itemChartRefresh);
groupChart.GroupStyle = NavBarGroupStyle.LargeIconsText;
navBar.Groups.Add(groupSettings);
groupSettings.ItemLinks.Add(itemEditSettings);
groupSettings.ItemLinks.Add(itemExport);
groupSettings.GroupStyle = NavBarGroupStyle.LargeIconsText;
navBar.ActiveGroup = groupChart;
navBar.LinkClicked += new NavBarLinkEventHandler(navBar_LinkClicked);
navBar.SelectedLinkChanged += navBar_SelectedLinkChanged;
navBar.LinkSelectionMode = LinkSelectionModeType.OneInGroupAndAllowAutoSelect;
navBar.EndUpdate();
}
void navBar_SelectedLinkChanged(object sender, DevExpress.XtraNavBar.ViewInfo.NavBarSelectedLinkChangedEventArgs e) {
string s = string.Format("'{0}' selected", e.Link.Caption);
listBoxControl1.Items.Add(s);
}
void navBar_LinkClicked(object sender, NavBarLinkEventArgs e) {
string s = string.Format("'{0}' clicked", e.Link.Caption);
listBoxControl1.Items.Add(s);
}
}
}
|
Form1.vb |
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports DevExpress.XtraNavBar
Namespace CreateNavBar
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Create a NavBarControl.
Dim navBar As New NavBarControl()
Me.Controls.Add(navBar)
navBar.Width = 150
navBar.Dock = DockStyle.Left
' Apply the "NavigationPaneView" style.
navBar.PaintStyleKind = NavBarViewKind.NavigationPane
' Create the 'Charts' navbar group.
Dim groupChart As New NavBarGroup("Charts")
' Display a large image in the group caption.
groupChart.LargeImage = My.Resources.chart_32x32
' Create an 'Area' item and assign an image to it from the project resources.
Dim itemChartArea As New NavBarItem("Area")
itemChartArea.LargeImage = My.Resources.area_32x32
' Create a 'Bar' item.
Dim itemChartBar As New NavBarItem("Bar")
itemChartBar.LargeImage = My.Resources.bar_32x32
' Create a disabled 'Refresh' item.
Dim itemChartRefresh As New NavBarItem("Refresh")
itemChartRefresh.LargeImage = My.Resources.refresh_32x32
itemChartRefresh.Enabled = False
'Assign an image collection to the NavBarControl.
'Images from this collection are used in the 'Settings' navbar group
navBar.LargeImages = imageCollection1
' Create the 'Settings' navbar group.
Dim groupSettings As New NavBarGroup("Settings")
' Display a large image in the group caption.
groupSettings.LargeImage = My.Resources.customize_32x32
' Create an 'Edit Settings' item and assign a large image to it by its index in the navBar.LargeImages collection.
Dim itemEditSettings As New NavBarItem("Edit Settings")
itemEditSettings.LargeImageIndex = 0
' Create an Export item and assign a large image to it by its index in the navBar.LargeImages collection.
Dim itemExport As New NavBarItem("Export")
itemExport.LargeImageIndex = 1
' Add the created items to the groups and the groups to the NavBarControl.
' Prevent excessive updates using the BeginUpdate and EndUpdate methods.
navBar.BeginUpdate()
navBar.Groups.Add(groupChart)
groupChart.ItemLinks.Add(itemChartArea)
groupChart.ItemLinks.Add(itemChartBar)
' Add a separator.
groupChart.ItemLinks.Add(New NavBarSeparatorItem())
groupChart.ItemLinks.Add(itemChartRefresh)
'Enable the display of large images in the group.
groupChart.GroupStyle = NavBarGroupStyle.LargeIconsText
navBar.Groups.Add(groupSettings)
groupSettings.ItemLinks.Add(itemEditSettings)
groupSettings.ItemLinks.Add(itemExport)
'Enable the display of large images in the group.
groupSettings.GroupStyle = NavBarGroupStyle.LargeIconsText
' Activate the 'Charts' group.
navBar.ActiveGroup = groupChart
' Specify the event handler to process item clicks.
AddHandler navBar.LinkClicked, AddressOf navBar_LinkClicked
' Specify the event handler to process item selection.
AddHandler navBar.SelectedLinkChanged, AddressOf navBar_SelectedLinkChanged
' Enable link selection.
' Each group can have a single selected link independent of other groups.
' When a group is activated and it has no selected link, the first link is auto-selected.
' At runtime, you will see that the SelectedLinkChanged event fires on group activation,
' while the LinkClicked event does not.
navBar.LinkSelectionMode = LinkSelectionModeType.OneInGroupAndAllowAutoSelect
navBar.EndUpdate()
' Manually select the second link:
'groupChart.SelectedLinkIndex = 1;
End Sub
Private Sub navBar_SelectedLinkChanged(ByVal sender As Object, ByVal e As DevExpress.XtraNavBar.ViewInfo.NavBarSelectedLinkChangedEventArgs)
Dim s As String = String.Format("'{0}' selected", e.Link.Caption)
listBoxControl1.Items.Add(s)
End Sub
Private Sub navBar_LinkClicked(ByVal sender As Object, ByVal e As NavBarLinkEventArgs)
Dim s As String = String.Format("'{0}' clicked", e.Link.Caption)
listBoxControl1.Items.Add(s)
End Sub
End Class
End Namespace
|