是否可以删除TabControl中所选选项卡上的虚线矩形和视觉样式?

时间:2013-04-09 12:38:05

标签: c# focus tabcontrol ownerdrawn

我在我的extendedtabcontol类上遇到问题,我无法摆脱所选标签上的虚线框或视觉样式框。我有自己的DrawItem(见下文),我已经从tabcontrol中覆盖了几个方法,我甚至覆盖了WndProc中的WM_SETFOCUS和WM_PAINT,但是框和高亮显示不会消失。是否有关闭它们(盒子或视觉样式)或一种简单的方法来绘制它们/阻止它们绘制?

用户可以判断选择了哪个选项卡,因为当其他选项卡为灰色时,它会以黑色绘制。

        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++;
        }
    }

我会张贴图片,但我没有声誉。 类似的问题例如: Can I remove the dotted focus rectangle over tabs on a TabControl?

0 个答案:

没有答案