邪风戏雨

青斗笠,绿蓑衣,斜风细雨不须归。

导航

给tabControl做背景

Posted on 2004-12-13 19:58  fdreg  阅读(2210)  评论(0)    收藏  举报

private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
  {
   Font fntTab;
   Brush bshBack;
   Brush bshFore;

   if ( e.Index == this.tabControl1.SelectedIndex)
   {
    fntTab = new Font(e.Font, FontStyle.Bold);
    bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.ControlDarkDark, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
    bshFore = Brushes.Red;
    //bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.LightSkyBlue , Color.LightGreen, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
    //bshFore = Brushes.Blue;
   }
   else
   {
    fntTab = e.Font;
    bshBack = new SolidBrush(SystemColors.ControlDark);
    bshFore = new SolidBrush(Color.Red);

    //bshBack = new SolidBrush(Color.White);
    //bshFore = new SolidBrush(Color.Black);
   }
    
   string tabName  = this.tabControl1.TabPages[e.Index].Text;
   StringFormat sftTab = new StringFormat();
   e.Graphics.FillRectangle(bshBack, e.Bounds);
   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);

  }