Back to Devexpress

BarManager.ForceLinkCreate() Method

windowsforms-devexpress-dot-xtrabars-dot-barmanager-cd53eaa2.md

latest5.2 KB
Original Source

BarManager.ForceLinkCreate() Method

Forces the manager to create item links based on bar items.

Namespace : DevExpress.XtraBars

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public virtual void ForceLinkCreate()
vb
Public Overridable Sub ForceLinkCreate

Remarks

Bar items are bar buttons, menu commands, static captions, and other elements that can be placed in a toolbar, menu, or ribbon. A single bar item can be placed in a toolbar and menu at the same time. This allows users to invoke commands in any convenient way.

For this purpose, the BarManager creates item links based on bar items. An item link represents the corresponding bar item in a toolbar, menu, or ribbon. You can use link properties to customize the bar item in the toolbar and menu differently (for example, you can specify a short caption in the toolbar and a detailed caption in the menu).

For performance reasons, item links are not created until the form is loaded. That is why changing link properties is not in effect until the BarManager is loaded. If you specify a link property in code before the BarManager is loaded (for example, in the form’s constructor), call the BarManager.ForceLinkCreate or BarManager.ForceInitialize method first.

csharp
using DevExpress.XtraBars;

public Form1() {
    InitializeComponent();
    bm.ForceInitialize();
    BarButtonItem bbiNew = new BarButtonItem(bm, "New");
    bbiNew.ImageUri.Uri = "New";
    BarItemLink link1 = bar1.AddItem(bbiNew);
    // The BeginGroup property is not in effect until the BarManager component is initialized.
    link1.BeginGroup = true;
}
vb
Imports DevExpress.XtraBars

Public Sub New()
    InitializeComponent()
    bm.ForceInitialize()
    Dim bbiNew As New BarButtonItem(bm, "New")
    bbiNew.ImageUri.Uri = "New"
    Dim link1 As BarItemLink = bar1.AddItem(bbiNew)
  ' The BeginGroup property is not in effect until the BarManager component is initialized.
    link1.BeginGroup = True
End Sub

You can also specify link properties in the Form.Load event that fires when the BarManager is already loaded.

csharp
this.Load += Form1_Load;

private void Form1_Load(object sender, EventArgs e) {
    BarButtonItem bbiNew = new BarButtonItem(bm, "New");
    bbiNew.ImageUri.Uri = "New";
    BarItemLink link1 = bar1.AddItem(bbiNew);
    // The BeginGroup property is not in effect until the BarManager component is initialized.
    link1.BeginGroup = true;
}
vb
AddHandler Me.Load, AddressOf Form1_Load

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim bbiNew As New BarButtonItem(bm, "New")
    bbiNew.ImageUri.Uri = "New"
    Dim link1 As BarItemLink = bar1.AddItem(bbiNew)
   ' The BeginGroup property is not in effect until the BarManager component is initialized.
    link1.BeginGroup = True
End Sub

The ForceLinkCreate() method fires the Load event.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ForceLinkCreate() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-create-information-panels/CS/EFCore/InfoPanelEF/InfoPanelEF.Win/LightStyleMainRibbonForm1.cs#L95

csharp
SynchronizeBarAndDockingControllerWithDefault();
ribbonControl.Manager.ForceLinkCreate();
statusMessagesHelper = new StatusMessagesHelper(barContainerStatusMessages);

See Also

Bar Item Links

Load

BarManager Class

BarManager Members

DevExpress.XtraBars Namespace