本文介绍了自定义TabPage标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想创建一个自定义TabPage标头,可以在其中定义背景色.
只是标题,而不是整个TabPage.

感谢您的帮助

HI everybody,

I would like to create a Custom TabPage Header where I can define the background color.
Just the header, not the whole TabPage.

Thanks for your Help

推荐答案

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
        Font TabFont;
        Brush BackBrush = new SolidBrush(Color.White); //Set background color
        Brush ForeBrush = new SolidBrush(Color.FromArgb(86, 125, 177));//Set foreground color
        if (e.Index == this.tabControl1.SelectedIndex)
        {
            TabFont = new Font(e.Font.FontFamily,10,FontStyle.Bold);

        }
        else
        {
        TabFont = e.Font;
        }
        string TabName = this.tabControl1.TabPages[e.Index].Text;
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        e.Graphics.FillRectangle(BackBrush, e.Bounds);
        Rectangle r = e.Bounds;
        r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
        e.Graphics.DrawString(TabName, TabFont, ForeBrush, r, sf);
        //Dispose objects
        sf.Dispose();
        if (e.Index == this.tabControl1.SelectedIndex)
        {
        TabFont.Dispose();
        BackBrush.Dispose();
        }
        else
        {
        BackBrush.Dispose();
        ForeBrush.Dispose();
        }
      }


在此代码中,您可以定义背景色和前景色.

可能会有所帮助,
Theingi Win


In this code you can defined background color and foreground color.

May be helpful,
Theingi Win



这篇关于自定义TabPage标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 17:30