Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable visual styles for just one control, and not its children?

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.

like image 539
Simon Avatar asked Nov 18 '08 11:11

Simon


1 Answers

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);
  }
}
like image 71
Hans Passant Avatar answered Nov 01 '22 19:11

Hans Passant