Articles in this section
Category / Section

How to possible to find out the number of rows painted in the WinForms TabControlAdv?

2 mins read

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

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