Janyou's blog

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

   ToolStripSplitButton 的button 部分没有Checked propery,下列方法简单的解决这个问题:

     在button 的checkd 时,额外绘制一些图形,效果如下:

         image

 

   1: using System.Drawing;
   2: using System.Drawing.Drawing2D;
   3: using System.Windows.Forms;
   4: using System.Windows.Forms.VisualStyles;
   5:  
   6: namespace  SplitButton
   7: {
   8:     public class ToolStripSplitButtonEx : ToolStripSplitButton
   9:     {
  10:         private bool @checked = false;
  11:       
  12:         public ToolStripSplitButtonEx()
  13:         {
  14:         }
  15:  
  16:         public bool Checked
  17:         {
  18:             get { return @checked; }
  19:             set
  20:             {
  21:                 @checked = value;
  22:                 Invalidate();
  23:             }
  24:         }
  25:  
  26:  
  27:         protected override void OnPaint(PaintEventArgs e)
  28:         {
  29:             if (@checked)
  30:             {
  31:                     Rectangle rect = ButtonBounds;
  32:                     using (Brush br = new LinearGradientBrush(rect,
  33:                                                               ProfessionalColors.ButtonCheckedGradientBegin,
  34:                                                               ProfessionalColors.ButtonCheckedGradientEnd,
  35:                                                               LinearGradientMode.Vertical))
  36:                     {
  37:                         e.Graphics.FillRectangle(br, rect);
  38:                     }
  39:  
  40:                     rect.Inflate(-1, -1);
  41:                     e.Graphics.DrawRectangle(Pens.Black, rect);
  42:                
  43:             }
  44:             base.OnPaint(e);
  45:         }
  46:     }
  47: }

Refences:

1.http://episteme.arstechnica.com/groupee/forums/a/tpc/f/6330927813/m/157009688731

   
 
posted on 2008-09-26 09:40  janyou  阅读(523)  评论(0编辑  收藏  举报