首页 > 代码库 > TabControl控件在左侧绘制tabPage页面

TabControl控件在左侧绘制tabPage页面

效果图:

技术分享

代码:

1.设置控件属性

   tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
   tabControl1.Alignment = TabAlignment.Left;
   tabControl1.SizeMode = TabSizeMode.Fixed;
   tabControl1.Multiline = true;
   tabControl1.ItemSize = new Size(50, 100);

2.设置事件

       private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            Rectangle tabArea = tabControl1.GetTabRect(e.Index);//主要是做个转换来获得TAB项的RECTANGELF
            RectangleF tabTextArea = (RectangleF)(tabControl1.GetTabRect(e.Index));
            Graphics g = e.Graphics;
            StringFormat sf = new StringFormat();//封装文本布局信息
            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment = StringAlignment.Center;
            Font font = this.tabControl1.Font;
            SolidBrush brush = new SolidBrush(Color.Black);//绘制边框的画笔
            g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf);
        }

TabControl控件在左侧绘制tabPage页面