I'm trying to remove dotted focus rectangle from my custom Tab Control
. I've tried everything and I could not remove that rectangle.
As you can see in the picture, the focus rectangle is disturbing in my application design.
Please help!
I'm trying to remove dotted focus rectangle from my custom Tab Control
. I've tried everything and I could not remove that rectangle.
As you can see in the picture, the focus rectangle is disturbing in my application design.
Please help!
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);
}
}