小问题系列<2> ---- 关于TabControl

01.将选项卡停靠左侧时,标题文字旋转方向的问题 

  当设置选项卡停靠左边时:

tabControl1.Alignment=System.Windows.Forms.TabAlignment.Left;

  可能会出现如下问题:

  tabcontrol_01_failed         

  解决后:          

   tabcontrol_01_Pass

 

  解决方法如下:

  1.首先调制成绘制模式

tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; 
tabControl1.Alignment = TabAlignment.Left ;


  2.将 DrawMode 属性设置为 OwnerDrawFixed时,每当 TabControl 需要绘制它的一个选项卡时,它就会引发 DrawItem 事件。因此要设置并注册DrawItem事件:  

//设置事件:
private Rectangle tabArea;
private RectangleF tabTextArea;
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
  tabArea = tabControl1.GetTabRect(e.Index);
  tabTextArea = tabArea;
  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);
}

//注册事件:
tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);

  参考:http://blog.csdn.net/jsnjlhb/article/details/4437872




posted @ 2012-03-10 13:40  蜗牛的未来  阅读(341)  评论(0编辑  收藏  举报