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);
        }

上一篇:Python学习之旅—生成器对象的send方法详解


下一篇:SQL批量删除用户表(先删除所有外键约束,再删除所有表)