[VB.NET,C#.NET] - TabControl的Alignment为Left或Right显示TabPage.Text问题

前端之家收集整理的这篇文章主要介绍了[VB.NET,C#.NET] - TabControl的Alignment为Left或Right显示TabPage.Text问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB.NET

Private Sub TabControl1_DrawItem( ByVal sender As System.Object, e System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
' Me.TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed ' 必须先改变模式(可将此句放在Load事件上)
Dim tabArea Rectangle
tabTextArea RectangleF
tabArea
= TabControl1.GetTabRect(e.Index)
tabTextArea
CType (TabControl1.GetTabRect(e.Index),RectangleF)
g Graphics e.Graphics
sf StringFormat New StringFormat()
sf.LineAlignment
StringAlignment.Center
sf.Alignment
StringAlignment.Center
font Font Me .TabControl1.Font
brush SolidBrush SolidBrush(Color.Black)
g.DrawString((
(sender,TabControl)).TabPages(e.Index).Text,font,brush,tabTextArea,sf)
End Sub

C#.NET

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 =  SolidBrush(Color.Black);
    g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text,sf);
}

猜你在找的VB相关文章