Back to Devexpress

BarManager.HighlightedLinkChanged Event

windowsforms-devexpress-dot-xtrabars-dot-barmanager-1495a441.md

latest4.5 KB
Original Source

BarManager.HighlightedLinkChanged Event

Fires immediately after the highlighted link has been changed.

Namespace : DevExpress.XtraBars

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event HighlightedLinkChangedEventHandler HighlightedLinkChanged
vb
<DXCategory("Events")>
Public Event HighlightedLinkChanged As HighlightedLinkChangedEventHandler

Event Data

The HighlightedLinkChanged event's data class is HighlightedLinkChangedEventArgs. The following properties provide information specific to this event:

PropertyDescription
LinkGets the currently highlighted link.
PrevLinkGets the previously highlighted link.

Remarks

Write a HighlightedLinkChanged event handler to perform specific actions each time the currently highlighted link is changed. The event parameter allows you to determine the previous and currently highlighted link. Note that this event fires when none of links was previously highlighted or when none of them becomes highlighted. The properties representing the currently and previously highlighted links can return null references in such cases.

If you want to determine the currently highlighted link directly from your code, use the BarManager.HighlightedLink property.

Example

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

See Also

HighlightedLink

BarManager Class

BarManager Members

DevExpress.XtraBars Namespace