效果圖:
代碼:
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);
}