10

I have a TabControl within a TabControl. I want the outer TabControl to show its tabs on the left. However, with Visual Styles enabled, left-aligned TabControls don't display properly. Can I disable Visual Styles for just the outer TabControl?

I'm aware of the third-party TabControl replacements - that's not what I'm after.

redsquare
  • 78,161
  • 20
  • 151
  • 159
Simon
  • 25,468
  • 44
  • 152
  • 266

1 Answers1

25

Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of the toolbox onto your form. Visual styles of the child controls are preserved.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class FixedTabControl : TabControl {
  [DllImportAttribute("uxtheme.dll")]
  private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

  protected override void OnHandleCreated(EventArgs e) {
    SetWindowTheme(this.Handle, "", "");
    base.OnHandleCreated(e);
  }
}
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • How could you achieve this for enabling visual styles for a button, I've disabled styles for my progress bar to have different colours. But i'd like my tabcontrol and my buttons to have the newer style. Is this possible? – Rhys Drury Apr 10 '13 at 16:18
  • Well, you are doing it the wrong way around. Use this exact same approach but only for the specific controls whose visual style you want to disable. Like that progress bar. – Hans Passant Apr 10 '13 at 16:41
  • By far the best solution I've found to this problem. Thanks! – Finch042 Sep 26 '13 at 06:37
  • Works perfectly for a progress bar I wanted to have changing colors. Still looks pretty sleek too! – Kaitlyn Aug 28 '15 at 19:27