Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Show scroll buttons in the headers area on a left-aligned tabcontrol

Haitam:

I have created a custom TabControl that has tabpages left-aligned with horizontal titles. I add tabpages dynamicly and I came across a problem that I need to solve but don't know how.

Usually, when a TabControl receives a lot of tabpages, it'll create 2 buttons to scroll between them, like this:

But with my custom TabControl, the buttons don't show up and instead, the tabpages headers start to take more place (horizontally), like this:

The code of my custom TabControl:


public class VerticalTabControl : TabControl
{


// Constructor
public VerticalTabControl()
{
Alignment = TabAlignment.Left;
SizeMode = TabSizeMode.Fixed;
ItemSize = new Size(35, 150);
DrawMode = TabDrawMode.OwnerDrawFixed;
}


protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);

Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

var tabPage = TabPages[e.Index];
var tabBounds = GetTabRect(e.Index);

using (SolidBrush b = new SolidBrush(e.State == DrawItemState.Selected ? Color.FromArgb(217, 228, 244) : DefaultBackColor))
{
g.FillRectangle(b, e.Bounds);
}

bool hasImg = false;
if (ImageList != null && tabPage.ImageIndex >= 0)
{
ImageList.Draw(g, tabBounds.X + 6, tabBounds.Y + (tabBounds.Height / 2 - ImageList.ImageSize.Height / 2), tabPage.ImageIndex);
hasImg = true;
}

using (SolidBrush b = new SolidBrush(e.State == DrawItemState.Selected ? Color.Black : e.ForeColor))
{
tabBounds.X += hasImg ? ImageList.ImageSize.Width + 10 : 6;
var textSize = g.MeasureString(tabPage.Text, Font);

if (tabPage.Tag != null && tabPage.Tag.ToString().Length > 0)
{
var tagFont = new Font(Font.FontFamily, Font.Size - 2);
var tagSize = g.MeasureString(tabPage.Tag.ToString(), tagFont);
g.DrawString(tabPage.Text, Font, b, tabBounds.X, tabBounds.Y + tabBounds.Height / 2 - (textSize.Height + tagSize.Height) / 2);
g.DrawString(tabPage.Tag.ToString(), tagFont, b, tabBounds.X, tabBounds.Y + tabBounds.Height / 2 - (textSize.Height + tagSize.Height) / 2 + textSize.Height);
}
else
{
g.DrawString(tabPage.Text, Font, b, tabBounds.X, tabBounds.Y + textSize.Height / 2);
}
}
}

}

Anyone has a solution for this? Do I really need to code this from scratch?

Thanks for the help!



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Show scroll buttons in the headers area on a left-aligned tabcontrol

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×