1

I'm trying to remove dotted focus rectangle from my custom Tab Control. I've tried everything and I could not remove that rectangle.

Tab Control Dialog

As you can see in the picture, the focus rectangle is disturbing in my application design.

Please help!

dngadelha
  • 1,314
  • 2
  • 11
  • 14

1 Answers1

4

To remove the focus cue, you have to set UserPaint to true, and then paint the entire tab control yourself, including the borders, text, backgrounds, highlighting, hot-tracking, etc.

The following code only paints the tab text and the background:

public class TC2 : TabControl {
    public TC2() {
        this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
    }

    protected override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);
        var g = e.Graphics;

        TabPage currentTab = this.SelectedTab;
        for (int i = 0; i < TabPages.Count; i++) {
            TabPage tp = TabPages[i];
            Rectangle r = GetTabRect(i);
            Brush b = (tp == currentTab ? Brushes.LightSteelBlue : Brushes.LightGray);
            g.FillRectangle(b, r);
            TextRenderer.DrawText(g, tp.Text, tp.Font, r, tp.ForeColor);
        }
    }

    protected override void OnPaintBackground(PaintEventArgs e) {
        base.OnPaintBackground(e);
    }
}
Loathing
  • 5,109
  • 3
  • 24
  • 35
  • My custom tab control already does this. Even with a custom paint still appears the focus rectangle. I do not know what to do :( – dngadelha Jul 18 '15 at 13:07
  • `DrawMode = TabDrawMode.OwnerDrawFixed` does not equal `SetStyle(UserPaint)`. At this point, you have to provide some code, otherwise it's guessing. – Loathing Jul 18 '15 at 17:11
  • @Loathing +1. I needed this. –  Aug 16 '16 at 06:23