0

作为操作(尤其是禁用)我的 TabControl 的一部分,我自己绘制它!

代码:

InitializeComponent();

this.TabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
this.TabControl.DrawItem += new DrawItemEventHandler(TabControlDrawItem);
this.TabControl.Selecting += new TabControlCancelEventHandler(TabControlSelecting);

...

private void TabControlDrawItem(object sender, DrawItemEventArgs e)
{
    TabPage page = m_tcView.TabPages[e.Index];
    e.Graphics.FillRectangle(new SolidBrush(page.BackColor), e.Bounds);            

    Rectangle paddedBounds = e.Bounds;
    int yOffset = (e.State == DrawItemState.Selected) ? -2 : 1;
    paddedBounds.Offset(1, yOffset);

    TextRenderer.DrawText(e.Graphics, page.Text, this.Font, paddedBounds, page.ForeColor);
}

private void TabControlSelecting(object sender, TabControlCancelEventArgs e)
{
    if (e.TabPage.Enabled == false)
    {
        e.Cancel = true;
    }
}

但我对外观和感觉并不满意!我希望它类似于VS2012生成的TabControl(见图)!需要进行哪些更改?

VS2012生成的TabControl

谢谢

4

0 回答 0