Articles in this section
Category / Section

How to customize the close button of the individual MDI child in WinForms TabbedGroupedMDIManager?

2 mins read

Customize the close button of specific MDI child

We can customize the size of the close button of the individual MDI child in TabbedGroupedMDIManager by deriving it's tab style renderer and overriding GetCloseButtonBounds() method

C#

//Rendering TabRendererOffice2007 since the TabbedGroupedMDIManager's 
//tabstyle is set as TabRendererOffice2007.
public class TabRendererMSOffice2007 : TabRendererOffice2007
{
   static TabUIDefaultProperties tabPanelPropertyExtender;
   // Exposes the default appearance properties to the tab panel renderer.
   public static new TabUIDefaultProperties TabPanelPropertyExtender
   {
       get { return tabPanelPropertyExtender; }
   }
   // Specifies the name by which this renderer will be identified.
   public static new string TabStyleName
   {
       get { return "MSOffice2007"; }
   }
   static TabRendererMSOffice2007()
   {
      tabPanelPropertyExtender = new TabUIDefaultProperties();
      TabRendererFactory.RegisterTabType(TabStyleName, typeof(TabRendererMSOffice2007), TabPanelPropertyExtender);
   }
   public TabRendererMSOffice2007(ITabControl parent, ITabPanelRenderer panelRenderer) : base(parent, panelRenderer)
   { }
   protected override RectangleF GetCloseButtonBounds(DrawTabEventArgs drawItemInfo)
   {
       // Get the close button bounds and change the size, as needed.
       RectangleF rect = base.GetCloseButtonBounds(drawItemInfo);
       rect.Width = 10;
       rect.Height = 10;
       return rect;
   }
}

VB

'Rendering TabRendererOffice2007 since the TabbedGroupedMDIManager's 
'tabstyle is set as TabRendererOffice2007.
Public Class TabRendererMSOffice2007
    Inherits TabRendererOffice2007
    Private Shared tabPanelPropertyExtender_Renamed As TabUIDefaultProperties
    ' Exposes the default appearance properties to the tab panel renderer.
    Public Shared Shadows ReadOnly Property TabPanelPropertyExtender() As TabUIDefaultProperties
        Get
             Return tabPanelPropertyExtender_Renamed
        End Get
    End Property
    ' Specifies the name by which this renderer will be identified.
    Public Shared Shadows ReadOnly Property TabStyleName() As String
        Get
             Return "MSOffice2007"
        End Get
    End Property
    Shared Sub New()
        tabPanelPropertyExtender_Renamed = New TabUIDefaultProperties()
        TabRendererFactory.RegisterTabType(TabStyleName, GetType(TabRendererMSOffice2007), TabPanelPropertyExtender)
    End Sub
    Public Sub New(ByVal parent As ITabControl, ByVal panelRenderer As ITabPanelRenderer)
       MyBase.New(parent, panelRenderer)
    End Sub
    Protected Overrides Function GetCloseButtonBounds(ByVal drawItemInfo As DrawTabEventArgs) As RectangleF
        'Get the close button bounds and change the size, as needed.
        Dim rect As RectangleF = MyBase.GetCloseButtonBounds(drawItemInfo)
        rect.Width = 10
        rect.Height = 10
        Return rect
    End Function
End Class

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied