解决当tabcontrol靠左时,字竖向显示的问题
this.tabControl.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl_DrawItem);
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.tabControl.SelectedIndex)
{
//fntTab = new Font(e.Font, FontStyle.Bold);
fntTab = e.Font;
// bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshBack = new SolidBrush(Color.LightGray);
bshFore = Brushes.Black;
}
else
{
fntTab = e.Font;
//bshBack = new SolidBrush(Color.Blue);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshFore = new SolidBrush(Color.Black);
}
string tabName = this.tabControl.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
sftTab.LineAlignment = StringAlignment.Center;
sftTab.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(bshBack, e.Bounds);
RectangleF recTab = (RectangleF)tabControl.GetTabRect(e.Index);//绘制区域
//Rectangle recTab = e.Bounds;
// recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}