Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
450
Ribbon to collapse (minimize) and expand on mouse movement
posted

I would like to be able to have my ribbon permanently minimized, then `expand` on mouse enter and `collapse` again on mouse leave.

The only events on the ToolbarManager I can see that might be useful is MouseEnterElement and MouseLeaveElement and in there set the

.minimized property of the ribbon. Even in those events the ribbon would minimize when going from one tool to another on the ribbon, I would then also need a way to check if the mouse is still over the ribbon or a toolbar to prevent `flashing`.

As far as I can tell though, these events only fire when the mouse enters or leaves a control on the ribbon, like a button or dropdown menu.

The events would then be skipped completely should the mouse wander over empty ribbon tab space or toolbar space.

 

Please advise if there is an easier way to accomplish this. Thanks in advance

 

Parents
  • 44743
    posted

    The MouseEnterElement and MouseLeaveElement event fire whenever the mouse moves to new UIElements. If you are over a big empty space, chances are it is displayed by a single UIElement and therfore the events shouldn't fire. However, I think I was able to imlement this. Try using the following code and let me know if this is what you are looking for (don't forget to hook up the event handlers for MouseEnterEement and MouseLeaveElement):

    public Form1()
    {
     InitializeComponent();

     this.ultraToolbarsManager1.Ribbon.IsMinimized = true;
    }

    private void ultraToolbarsManager1_MouseEnterElement( object sender, UIElementEventArgs e )
    {
     this.ultraToolbarsManager1.Ribbon.IsMinimized = this.ShouldMinimizeRibbon( e.Element );
    }

    private void ultraToolbarsManager1_MouseLeaveElement( object sender, UIElementEventArgs e )
    {
     // When leaving elements, we only want to collapse the ribbon in some case.
     //If it is already collapsed, we don't have to do anything.
     if ( this.ultraToolbarsManager1.Ribbon.IsMinimized )
      return;

     Point screenPoint = Cursor.Position;
     Point formClientPoint = this.PointToClient( screenPoint );
     Control controlAtPoint = this.GetChildAtPoint( formClientPoint, GetChildAtPointSkip.Invisible );

     UltraToolbarsDockArea dockArea = controlAtPoint as UltraToolbarsDockArea;

     // If the mouse is not over a dock area, immediately collapse the ribbon and return.
     if ( dockArea == null )
     {
      this.ultraToolbarsManager1.Ribbon.IsMinimized = true;
      return;
     }

     UIElement mainElement = ( (IUltraControlElement)dockArea ).MainUIElement;
     Point dockAreaClientPoint = dockArea.PointToClient( screenPoint );

     if ( mainElement != null )
     {
      UIElement childElement = mainElement.ElementFromPoint( dockAreaClientPoint );

      // If the ribbon should be collapsed based on the current element the mouse is over, collapse it.
      if ( this.ShouldMinimizeRibbon( childElement ) )
       this.ultraToolbarsManager1.Ribbon.IsMinimized = true;
     }
    }

    private bool ShouldMinimizeRibbon( UIElement mouseOverElement )
    {
     // When the mouse goes over the tab line element, the minimized state should not change
     if ( mouseOverElement is TabLineUIElement )
      return this.ultraToolbarsManager1.Ribbon.IsMinimized;

     // Show the ribbon tabs if the mouse goes over a ribbon tab item or an element on a ribbon tab page
     return
      mouseOverElement.GetAncestor( typeof( RibbonTabItemUIElement ) ) == null &&
      mouseOverElement.GetAncestor( typeof( RibbonTabPageUIElement ) ) == null;
    }

Reply Children