0

I am having a problem on my extendedtabcontol class, I cannot get rid of the dotted box or the visual style box on the selected tab. I have my own DrawItem (see below), I have overridden several methods from the tabcontrol and I have even overridden the WM_SETFOCUS and WM_PAINT in WndProc but the box and highlight will not go away. Is there anyway to turn them off (the box or visual style) or a simple way to draw over them / stop them drawing?

The user can tell which tab is selected because it is drawn in black when the others are grey.

        protected void OnDrawItem(object sender, DrawItemEventArgs e)
    {

       // VisualStyleRenderer renderer =
       // new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Disabled);
        DrawItemState ds = e.State;
        SolidBrush mybrush = new SolidBrush(Color.FromArgb(255, 151, 0, 11));
        Rectangle tabArea2 = new Rectangle(0, 0, this.Size.Width+10, this.Size.Height+10);

        //renderer.DrawBackground(e.Graphics, tabArea2);
        e.Graphics.FillRectangle(mybrush, tabArea2);
        int i = 0;

        foreach (TabPage tb in this.TabPages)
        {               
            Rectangle tabArea = this.GetTabRect(i);
            Point newp = new Point(tabArea.Location.X,tabArea.Location.Y + 2);
            tabArea.Location = newp;
            if (this.SelectedIndex != i)
            {
                RectangleF tabTextArea = (RectangleF)this.GetTabRect(i);
                e.Graphics.DrawImage(global::Config.Properties.Resources.Tab2, tabArea.Location);
            }
            else
            {
                e.Graphics.DrawImage(global::Config.Properties.Resources.Tab1, tabArea.Location);
            }
            SizeF size = e.Graphics.MeasureString(tb.Name.ToString().Trim(), drawFont);
            PointF pf = new PointF();
            pf.X = tabArea.X + (tabArea.Width / 2) - (size.Width/2);
            pf.Y = tabArea.Y + (tabArea.Height / 2) - (size.Height/2);
            e.Graphics.DrawString(tb.Name.ToString().Trim(), drawFont, drawBrush, pf);

            i++;
        }
    }

I would post an image but I don't have the reputation. Similar question for example: Can I remove the dotted focus rectangle over tabs on a TabControl?

Community
  • 1
  • 1
Adrian
  • 1
  • It is basically done by overriding outline and border properties. google ? – Sakthivel Apr 09 '13 at 12:44
  • Sorry dude but can you narrow it down a little more? Are they Tabcontrol methods/properties or the TabPages? Because I had a check on MSDN and the only useful looking one I found was .BorderWidth which was only a get and no set. I tried changing the Tabs Rectangle but that didn't do the trick either. I found this but I think its for WFP? [link](http://stackoverflow.com/questions/4286878/how-to-disable-the-dashed-contour-for-tabitem) This has lots of border config but I couldn't work out the needed part.[link](http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition) – Adrian Apr 09 '13 at 14:51

0 Answers0