Back to Devexpress

How to: Customize Font Settings for Specific Items

windowsforms-5442-controls-and-libraries-ribbon-bars-and-menu-examples-bars-how-to-customize-font-settings-for-specific-items.md

latest2.4 KB
Original Source

How to: Customize Font Settings for Specific Items

  • Nov 13, 2018

The following example highlights the hovered bar item with bold font.

  1. Create two fonts with different font styles - Bold and Regular.
  2. Handle the BarManager.HighlightedLinkChanged event. Use e.Link and e.PrevLink parameters to switch fonts.

csharp
using DevExpress.XtraBars; 

namespace Highlight-Hovered-BarItem {
  public partial class Form1 : DevExpress.XtraEditors.XtraForm {
    Font boldFont;
    Font regularFont;
    public Form1() {
      InitializeComponent();
      boldFont = new Font(barManager1.GetController().AppearancesBar.ItemsFont, FontStyle.Bold);
      regularFont = new Font(barManager1.GetController().AppearancesBar.ItemsFont, FontStyle.Regular);
      barManager1.HighlightedLinkChanged += BarManager1_HighlightedLinkChanged;
   }

    private void BarManager1_HighlightedLinkChanged(object sender, HighlightedLinkChangedEventArgs e) {
      if (e.PrevLink != null && e.PrevLink.Bar == barBrowser)
        e.PrevLink.Item.ItemAppearance.SetFont(regularFont);
      if (e.Link != null && e.Link.Bar == barBrowser)
        e.Link.Item.ItemAppearance.SetFont(boldFont);
    }
  }
}
vb
Imports DevExpress.XtraBars

Namespace Highlight-Hovered-BarItem
  Partial Public Class Form1
      Inherits DevExpress.XtraEditors.XtraForm

    Private boldFont As Font
     Private regularFont As Font
     Public Sub New()
       InitializeComponent()
       boldFont = New Font(barManager1.GetController().AppearancesBar.ItemsFont, FontStyle.Bold)
       regularFont = New Font(barManager1.GetController().AppearancesBar.ItemsFont, FontStyle.Regular)
       AddHandler barManager1.HighlightedLinkChanged, AddressOf BarManager1_HighlightedLinkChanged
     End Sub

     Private Sub BarManager1_HighlightedLinkChanged(ByVal sender As Object, ByVal e As HighlightedLinkChangedEventArgs)
       If e.PrevLink IsNot Nothing AndAlso e.PrevLink.Bar = barBrowser Then
          e.PrevLink.Item.ItemAppearance.SetFont(regularFont)
       End If
       If e.Link IsNot Nothing AndAlso e.Link.Bar = barBrowser Then
          e.Link.Item.ItemAppearance.SetFont(boldFont)
       End If
     End Sub
  End Class
End Namespace