)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to programmatically dock the XPMenus bar in WinForms CommandBar?

Platform: WinForms |
Control: CommandBarController |
Published Date: February 10, 2020 |
Last Revised Date: February 10, 2020

Dock the XPMenus bar

The XPMenus bar cannot be docked directly since it is not of the type control. So first, get the CommandBar that hosts this bar using the MainFrameBarManager’s GetBarControl method and then dock this CommandBar like any other dockable control. Please refer the below code snippet which illustrates this:

C#

CommandBar cmdbar = this.mainFrameBarManager1.GetBarControl(this.bar1);
cmdbar.DockState = CommandBarDockState.Left;
this.RecalcBarLayout(cmdbar);
Private void RecalcBarLayout(CommandBar cmdbar)
{
   // Call method RedockIfNeeded
   MethodInfo mInfo = typeof(CommandBar).GetMethod("RedockIfNeeded", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic);
   if (mInfo != null)
   {
      mInfo.Invoke(cmdbar, new object[] { });
   }
   // Call method OnCommandBarStateChanged
   mInfo = typeof(CommandBar).GetMethod("OnCommandBarStateChanged", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic);
   if (mInfo != null)
   {
      mInfo.Invoke(cmdbar, new object[] { EventArgs.Empty });
   }
}

VB

Dim cmdbar As CommandBar = MainFrameBarManager1.GetBarControl(Bar1)
cmdbar.DockState = CommandBarDockState.Left
Me.RecalcBarLayout(cmdbar)
Private Sub RecalcBarLayout(ByVal cmdbar As CommandBar)
   ' Call method RedockIfNeeded
   Dim mInfo As MethodInfo = GetType(CommandBar).GetMethod("RedockIfNeeded", BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.NonPublic)
   If Not mInfo Is Nothing Then
       mInfo.Invoke(cmdbar, New Object() {})
   End If
   ' Call method OnCommandBarStateChanged
   mInfo = GetType(CommandBar).GetMethod("OnCommandBarStateChanged", BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.NonPublic)
   If Not mInfo Is Nothing Then
       mInfo.Invoke(cmdbar, New Object() {EventArgs.Empty})
   End If
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon