Articles in this section
Category / Section

How to prevent tabs from getting realigned in WinForms TabControlAdv?

2 mins read

Prevent tabs from getting realigned when in multiline mode

KeepSelectedTabInFrontRow was added in version 1.6.1.0 to address this issue. For earlier versions, please derive from our base TabControlExt class and do the following. This code will not move the selected tab to the front row when in Multiline mode:

C#

// Custom tab control will prevent tab realignment in Multiline mode.
public class MyTabControlExt : TabControlExt 
{
   // Plugin the custom MyMultilineTabPanelRenderer class.
   protected override void RendererChanged(TabPanelRenderer rendererNew) 
   {
       if(rendererNew == null && this.Multiline) 
       {
           rendererNew = new MyMultilineTabPanelRenderer(this);
       }
       base.RendererChanged(rendererNew);
   } 
}
// Custom MyMultilineTabPanelRenderer to prevent tab realignment.
public class MyMultilineTabPanelRenderer : MultilineTabPanelRenderer 
{
   public MyMultilineTabPanelRenderer(ITabControl parent) : base(parent) { }
   protected override void ValidateSelectedTabsPosition() 
   {
       // Don’t call the base class method which will try to move the selected tab to the front row.
   } 
}

VB

'Custom tab control will prevent tab realignment in Multiline mode.
Public Class MyTabControlExt Inherits TabControlExt
   ' Plugin the custom MyMultilineTabPanelRenderer class.
   Protected Overrides Sub RendererChanged(ByVal rendererNew As TabPanelRenderer)
       If rendererNew Is Nothing AndAlso Me.Multiline Then
          rendererNew = New MyMultilineTabPanelRenderer(Me)
       End If
       MyBase.RendererChanged(rendererNew)
End Sub
'RendererChanged End Class ’MyTabControlExt 
'Custom MyMultilineTabPanelRenderer to prevent tab realignment.
Public Class MyMultilineTabPanelRenderer Inherits MultilineTabPanelRenderer
   Public Sub New(ByVal parent As ITabControl)
       MyBase.New(parent)
   End Sub
   Protected Overrides Sub ValidateSelectedTabsPosition() 
   End Sub
   'ValidateSelectedTabsPosition
End Class
'MyMultilineTabPanelRenderer
'Don’t call the base class method which will try to move the selected tab

 

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