)
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 possible to find out the number of rows painted in the WinForms TabControlAdv?

Platform: WinForms |
Control: TabControlAdv |
Published Date: April 30, 2011 |
Last Revised Date: February 3, 2020

Count the painted rows in TabControlAdv

It is possible by deriving TabControlAdv and count the number of rows when TabPageAdv is painted.

C#

public int GetNumOfRows()
{
    float minHeight = 0, currentLineHeight = 0, maxHeight = 0;
    int rows = 1;
    SizeF preferedTabSize = SizeF.Empty;
    SizeF overlappedSize = SizeF.Empty;
    Graphics g = this.CreateGraphics();
    SizeF prefSize = new SizeF(this.ClientRectangle.Width, this.ClientRectangle.Height);
overlappedSize = TabRendererFactory.GetRegisteredExtender
(this.m_tabPanelRenderer.TabPanelData.TabStyle).GetOverlapSize(this.m_tabPanelRenderer.TabPanelData.TabSize);
    overlappedSize.Height += this.m_tabPanelRenderer.TabPanelData.AdjustTopGap;
    float usedUpLineWidth = overlappedSize.Width;
    float availableWidth = prefSize.Width;
    int i=0;
    foreach (ITabRenderer render in this.m_tabPanelRenderer.Renderers)
    {
       preferedTabSize = ((ITabRenderer)this.m_tabPanelRenderer.Renderers[i]).GetPreferredSize(g);
       if (preferedTabSize.Width + usedUpLineWidth <= availableWidth || usedUpLineWidth <= overlappedSize.Width)
       {
           // enough space available in current line
           usedUpLineWidth += preferedTabSize.Width;
       }
       else
       {
           // move to next line
           minHeight += currentLineHeight;
           rows++;
           // This item becomes the first item in the new line
           usedUpLineWidth = overlappedSize.Width + preferedTabSize.Width;
           if (maxHeight < currentLineHeight)
              maxHeight = currentLineHeight;
              currentLineHeight = 0F;
        }
        if (currentLineHeight < preferedTabSize.Height)
           currentLineHeight = preferedTabSize.Height;
           i++;
    }
    return rows;
}
public bool ShouldDrawVisible(ITabData tdata)
{
    return (tdata.TabVisible);
}

VB

Public Function GetNumOfRows() As Integer
    Dim minHeight As Single = 0, currentLineHeight As Single = 0, maxHeight As Single = 0
    Dim rows As Integer = 1
    Dim preferedTabSize As SizeF = SizeF.Empty
    Dim overlappedSize As SizeF = SizeF.Empty
    Dim g As Graphics = Me.CreateGraphics()
    Dim prefSize As SizeF = New SizeF(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
    overlappedSize = TabRendererFactory.GetRegisteredExtender (Me.m_tabPanelRenderer.TabPanelData.TabStyle).GetOverlapSize(Me.m_tabPanelRenderer.TabPanelData.TabSize)
    overlappedSize.Height += Me.m_tabPanelRenderer.TabPanelData.AdjustTopGap
    Dim usedUpLineWidth As Single = overlappedSize.Width
    Dim availableWidth As Single = prefSize.Width
    Dim i As Integer=0
    For Each render As ITabRenderer In Me.m_tabPanelRenderer.Renderers
       preferedTabSize = (CType(Me.m_tabPanelRenderer.Renderers(i), ITabRenderer)).GetPreferredSize(g)
      If preferedTabSize.Width + usedUpLineWidth <= availableWidth OrElse usedUpLineWidth <= overlappedSize.Width
        Then
         '' enough space available in current line
        usedUpLineWidth += preferedTabSize.Width
      Else
        '' move to next line
        minHeight += currentLineHeight
        rows += 1
        '' This item becomes the first item in the new line
        usedUpLineWidth = overlappedSize.Width + preferedTabSize.Width
        If maxHeight < currentLineHeight Then
           maxHeight = currentLineHeight
        End If
        currentLineHeight = 0F
      End If
     If currentLineHeight < preferedTabSize.Height Then
        currentLineHeight = preferedTabSize.Height
     End If
     i += 1
     Next render
   Return rows
End Function
Public Function ShouldDrawVisible(ByVal tdata As ITabData) As Boolean
   Return (tdata.TabVisible)
End Function

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