TabRenderer without visible styles?

I want to create a custom TabControl with custom functions.

To do this, I inherited the Panel class and redefined the OnPaint method for drawing using the TabRenderer class.

The problem is that TabRenderer only works when the visual style is turned on (it can be checked using TabRenderer.IsSupported ), but what should I do if the visual styles are disabled?

In this case, I thought of using the ControlPaint class to draw tabs without visual styles, but it does not have tab-related drawing methods. I want it to basically behave like a regular TabControl .

+6
c # winforms visual-styles
source share
2 answers

You have to do it yourself, because there is no published API for this. Hope it is relatively easy to do this not visually.

You can draw the border of the panel using ControlPaint.DrawBorder3D and use the following buttons for this:

 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); 
+5
source share

This is the answer there, but is it possible that you can use wpf? As you can see from the answer above, pain in the ear sets up controls in winforms, where, like in WPF, every control is not needed. This means that you control what is displayed and how it looks completely.

0
source share

All Articles