0

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

我会发布一张图片,但我没有声誉。例如类似的问题: 我可以删除 TabControl 上选项卡上的虚线焦点矩形吗?

4

0 回答 0