TabRenderer with no visual styles enabled?
Asked Answered
F

2

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.

Freida answered 5/4, 2010 at 10:58 Comment(2)
In what way do you want your custom TabControl to be different from System.Windows.Forms.TabControl ?Blueprint
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.Freida
W
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);
Wharfage answered 9/4, 2010 at 12:45 Comment(1)
you could simplify this a lot using SystemPens - msdn.microsoft.com/en-us/library/system.drawing.systempens.aspxEnlarge
S
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.

Samala answered 13/4, 2010 at 14:35 Comment(1)
Thanks for the suggestion, but i need to support windows 2000 so WPF is not an option for me right now.Freida

© 2022 - 2024 — McMap. All rights reserved.