Search code examples
ribbondotnetbar

Resize a control inside a Ribbon Panel


I have a form with a ribbon bar and I want the controls that are on the RibbonPanel to resize with the rest of the form. The docked RibbonControl resizes fine and the RibbonPanel resizes with it but the controls that Docked/Anchored on the RibbonPanel do not resize.

How do you get controls on a ribbon panel to Dock or Anchor correctly?


Solution

  • For a work around I placed a normal Panel control inside of the RibbonPanel control, and docked all the controls I want to resize in that panel. Using a simple resize method and a couple event handlers to dynamically resize that panel, the controls now Anchor and Dock normally while on a RibbonPanel.

    Private Sub Form1_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
        Resize()
    End Sub
    
    Private Sub RibbonControl1_SelectedRibbonTabChanged(sender As System.Object, e As System.EventArgs) Handles RibbonControl1.SelectedRibbonTabChanged
        Resize()
    End Sub
    
    Private Sub Resize()
        Select Case RibbonControl1.SelectedRibbonTabItem.Name
            Case "RibbonTabItem1"
                Panel1.Size = RibbonPanel1.Size
            Case "RibbonTabItem2"
                Panel2.Size = RibbonPanel2.Size
            Case ...
        End Select
    End Sub