VB.NET
Private
Sub
TabControl1_DrawItem(
ByVal
sender
As
System.Object,
ByVal
e
As
System.Windows.Forms.DrawItemEventArgs)
Handles
TabControl1.DrawItem
' Me.TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed ' 必须先改变模式(可将此句放在Load事件上)
Dim tabArea As Rectangle
Dim tabTextArea As RectangleF
tabArea = TabControl1.GetTabRect(e.Index)
tabTextArea = CType (TabControl1.GetTabRect(e.Index), RectangleF)
' Me.TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed ' 必须先改变模式(可将此句放在Load事件上)
Dim tabArea As Rectangle
Dim tabTextArea As RectangleF
tabArea = TabControl1.GetTabRect(e.Index)
tabTextArea = CType (TabControl1.GetTabRect(e.Index), RectangleF)
Dim g As Graphics = e.Graphics
Dim sf As StringFormat = New StringFormat()
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
Dim font As Font = Me .TabControl1.Font
Dim brush As SolidBrush = New SolidBrush(Color.Black)
g.DrawString(( CType (sender, TabControl)).TabPages(e.Index).Text, font, brush, tabTextArea, sf)
End Sub
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { //this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; // 必须先改变模式(可将此句放在Load事件上) Rectangle tabArea; RectangleF tabTextArea; tabArea = tabControl1.GetTabRect(e.Index); 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); }