以下内容参考过两篇博客来实践的  具体链接找不到了。

设置属性:

 

   选项卡的高和款设置

 

 

 

事件:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {

            Font fntTab;
            Brush bshBack;
            Brush bshFore;
            bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
            ///选中时字体颜色为蓝色
            if (e.Index == this.tabControl1.SelectedIndex)
            {
                fntTab = new Font(e.Font, FontStyle.Bold);
                bshFore = Brushes.Blue;
            }
            else
            {
                fntTab = e.Font;
                bshFore = new SolidBrush(Color.Black);
            }
            string tabName = this.tabControl1.TabPages[e.Index].Text;
            StringFormat sftTab = new StringFormat();
            sftTab.LineAlignment = StringAlignment.Center; //居中
            sftTab.Alignment = StringAlignment.Center;
            e.Graphics.FillRectangle(bshBack, e.Bounds);
             
            Rectangle recTab = e.Bounds;
            recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
            e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);

            ////设置选项卡图标
            //Bitmap b = new Bitmap(TabImageList.Images[e.Index]);
            //e.Graphics.DrawImage(b,e.Bounds);
        }
View Code

 

 显示效果:

 

posted on 2020-02-24 12:03  FL0528  阅读(927)  评论(0)    收藏  举报