当我将绘图模式更改为OwnerDrawFixed TabControl时,将外观更改为3D

时间:2019-05-21 16:33:38

标签: c# winforms

我想从代码中绘制自己的Tab控件,并通过在DrawItem事件上调用tabControl1_DrawItem方法来成功实现此目的。

但是,当我将“绘图模式”更改为OwnerDrawFixed时,突然整个选项卡控件显示为3D,而以前,当“绘图模式”设置为“普通”时,它显示为2D。而且我无法弄清楚哪个属性会影响此效果,以及如何实现2D?

这是方法:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            TabPage page = tabControl1.TabPages[e.Index];
            StringFormat drawFormat = new StringFormat();
            drawFormat.Alignment = StringAlignment.Center;
            drawFormat.LineAlignment = StringAlignment.Center;

            var tabArea = tabControl1.GetTabRect(e.Index);

            RectangleF  tabTextArea = tabControl1.GetTabRect(e.Index);

            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Empty);


            if (!page.Enabled)
            {
                using (SolidBrush brush = new SolidBrush(SystemColors.GrayText))
                {
                    g.DrawRectangle(p, tabArea);
                    e.Graphics.DrawString(page.Text, page.Font, brush, tabTextArea, drawFormat);
                }
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(page.ForeColor))
                {
                    g.DrawRectangle(p, tabArea);
                    e.Graphics.DrawString(page.Text, page.Font, brush, tabTextArea, drawFormat);
                }
            }
        }

0 个答案:

没有答案