6

I want to draw a custom TabControl with custom functionality.

To do this, i inherited the Panel class and overrided OnPaint method to draw with TabRenderer class.

The problem is that TabRenderer working only when visual styles enabled (can be checked with TabRenderer.IsSupported), but what should i do if visual styles disabled?

In this case, I thought using the ControlPaint class to draw tabs without visual styles, but it has no draw methods related to Tabs. I want it basically to behave visually like the regular TabControl.

DxCK
  • 4,402
  • 7
  • 50
  • 89
  • In what way do you want your custom `TabControl` to be different from `System.Windows.Forms.TabControl` ? – Dynami Le Savard Apr 08 '10 at 20:35
  • Allow animations as the icon of a Tab, Allow custom drown X button on each Tab, Changing the location and drawing of the left & right buttons when the tab controls dont fit the width of the control, allowing right click on a tab, allow closing with the middle mouse button, allowing drag & drop tabpages... I want tabs functionally like in firefox. – DxCK Apr 09 '10 at 10:22

2 Answers2

5

You have to draw it by yourself, because there is not published API for this. Hopefully this is relatively easy to do it in non-visualstyles way.

You can draw pane border with ControlPaint.DrawBorder3D and use something like the following code for buttons:

int Top = bounds.Top;
int Bottom = bounds.Bottom - 1;
int Sign = 1;

if (tabStrip.EffectiveOrientation == TabOrientation.Bottom)
{
    Top = bounds.Bottom - 1;
    Bottom = bounds.Top;
    Sign = -1;
}

using (Pen OuterLightBorderPen = new Pen(SystemColors.ControlLightLight))
{
    e.Graphics.DrawLine(OuterLightBorderPen, bounds.Left, Bottom, bounds.Left, Top + 2 * Sign);
    e.Graphics.DrawLine(OuterLightBorderPen, bounds.Left, Top + 2 * Sign, bounds.Left + 2, Top);
    e.Graphics.DrawLine(OuterLightBorderPen, bounds.Left + 2, Top, bounds.Right - 3, Top);
}

using (Pen InnerLightBorderPen = new Pen(SystemColors.ControlLight))
{
    e.Graphics.DrawLine(InnerLightBorderPen, bounds.Left + 1, Bottom, bounds.Left + 1, Top + 2 * Sign);
    e.Graphics.DrawLine(InnerLightBorderPen, bounds.Left + 2, Top + 1 * Sign, bounds.Right - 3, Top + 1 * Sign);
}

using (Pen OuterDarkBorderPen = new Pen(SystemColors.ControlDarkDark))
{
    e.Graphics.DrawLine(OuterDarkBorderPen, bounds.Right - 2, Top + 1 * Sign, bounds.Right - 1, Top + 2 * Sign);
    e.Graphics.DrawLine(OuterDarkBorderPen, bounds.Right - 1, Top + 2 * Sign, bounds.Right - 1, Bottom);
}

using (Pen InnerDarkBorderPen = new Pen(SystemColors.ControlDark))
    e.Graphics.DrawLine(InnerDarkBorderPen, bounds.Right - 2, Top + 2 * Sign, bounds.Right - 2, Bottom);
arbiter
  • 9,447
  • 1
  • 32
  • 43
  • 3
    you could simplify this a lot using SystemPens - http://msdn.microsoft.com/en-us/library/system.drawing.systempens.aspx – Simon Apr 13 '10 at 14:37
0

This is an "out there" answer but is it possible that you could use wpf? As you can see from the answer above it is a pain in the ear to customise controls in winforms where as in WPF each control is lookless. This means that you control what is rendered and how it looks completely.

deanvmc
  • 5,957
  • 6
  • 38
  • 68
  • Thanks for the suggestion, but i need to support windows 2000 so WPF is not an option for me right now. – DxCK Apr 13 '10 at 17:09