XPButton xp按钮

public class XPButton:System.Windows.Forms.Button

{

 private bool mouseover=false;

 public XPButton()

 {

  //

  // TODO: 在此处添加构造函数逻辑

  //

  this.Cursor = System.Windows.Forms.Cursors.Hand;

 }

 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)

 {

  // base.OnPaint (e);

  // System.Drawing.Graphics pp=this.CreateGraphics();

  // e.Graphics.Clear(Color.Transparent);

  // e.Graphics.DrawEllipse(new System.Drawing.Pen(System.Drawing.Color.WhiteSmoke,5),0,0,this.Width,this.Height);

  // System.Drawing.SolidBrush dd=new SolidBrush(System.Drawing.Color.WhiteSmoke);

  // e.Graphics.FillEllipse(dd,0,0,this.Width,this.Height);

 

  // (this.BackColor.ToString ())

//  Color c5 = Color.FromArgb(255,255,255);
  Color c5 = Color.FromArgb(200,200,200);
  Color c2 = Color.FromArgb(255,255,255);

  if(mouseover)

  {

   c5=Color.FromArgb(245,245,245);

   c2=Color.FromArgb(192,192,192);

  }

  Brush b = new System.Drawing.Drawing2D.LinearGradientBrush

   (ClientRectangle, c5, c2, LinearGradientMode.Vertical);

  //System.Drawing.Region=new Region(

  int offsetwidth=this.Width/50;

  Point[] points=new Point[8];

  points[0].X=offsetwidth;

  points[0].Y=0;


  points[1].X=this.Width-offsetwidth;

  points[1].Y=0;


  points[2].X=this.Width;

  points[2].Y=offsetwidth;


  points[3].X=this.Width;

  points[3].Y=this.Height-offsetwidth;


  points[4].X=this.Width-offsetwidth;

  points[4].Y=this.Height;


  points[5].X=offsetwidth;

  points[5].Y=this.Height;


  points[6].X=0;

  points[6].Y=this.Height-offsetwidth;


  points[7].X=0;

  points[7].Y=offsetwidth;

  // e.Graphics.FillRectangle (b, ClientRectangle);

  e.Graphics.FillPolygon(b,points,FillMode.Winding);

  if(this.Focused)

  {

   int offsetwidth1=(this.Width-5)/50+2;

   Point[] points1=new Point[8];

   points1[0].X=offsetwidth1;

   points1[0].Y=2;


   points1[1].X=this.Width-offsetwidth1;

   points1[1].Y=2;


   points1[2].X=this.Width-1;

   points1[2].Y=offsetwidth1;


   points1[3].X=this.Width-1;

   points1[3].Y=this.Height-offsetwidth1;


   points1[4].X=this.Width-offsetwidth1;

   points1[4].Y=this.Height-1;


   points1[5].X=1;

   points1[5].Y=this.Height-1;


   points1[6].X=2;

   points1[6].Y=this.Height-offsetwidth1;


   points1[7].X=2;

   points1[7].Y=offsetwidth1;

   // e.Graphics.DrawPolygon(new Pen(Color.Yellow,2),points1);

   Pen p=new Pen(Color.Orange,2);

   Pen p1=new Pen(Color.Wheat,2);

   //p.DashStyle=DashStyle.DashDot;

   e.Graphics.DrawLine(p1,points1[0],points1[1]);


   e.Graphics.DrawLine(p,points1[1],points1[2]);

   e.Graphics.DrawLine(p,points1[2],points1[3]);

   e.Graphics.DrawLine(p,points1[3],points1[4]);

   e.Graphics.DrawLine(p,points1[4],points1[5]);

   e.Graphics.DrawLine(p,points1[5],points1[6]);

   e.Graphics.DrawLine(p1,points1[6],points1[7]);

   e.Graphics.DrawLine(p1,points1[7],points1[0]);

  }

  e.Graphics.DrawPolygon(new Pen(Color.LightSteelBlue,0),points);
  
  StringFormat drawFormat = new StringFormat();

  drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;

  drawFormat.LineAlignment=StringAlignment.Center;

  drawFormat.Alignment=System.Drawing.StringAlignment.Center;

  e.Graphics.DrawString(this.Text,this.Font,new LinearGradientBrush(this.ClientRectangle,Color.Black,Color.Black,LinearGradientMode.Vertical),this.ClientRectangle,drawFormat);

  b.Dispose();


 }

 protected override void OnLeave(EventArgs e)

 {

  base.OnLeave (e);

 }


 // protected override void OnMouseHover(EventArgs e)

 // {

 //

 // mouseover=true;

 // this.Invalidate(false);

 // base.OnMouseHover (e);

 // }

 protected override void OnMouseEnter(EventArgs e)

 {

  mouseover=true;

  this.Invalidate(false);

  base.OnMouseEnter (e);

 }


 protected override void OnNotifyMessage(System.Windows.Forms.Message m)

 {

  base.OnNotifyMessage (m);

 }


 protected override void OnMouseLeave(EventArgs e)

 {

  mouseover=false;

  this.Invalidate(false);

  base.OnMouseLeave (e);

 }

 private void DrawButton( System.Drawing.Graphics g)

 {


 }

 protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)

 {


  // Color c5 = Color.FromArgb

  // (255,255,255);

  // Color c2 = Color.FromArgb

  // (192,192,192);

  // if(mouseover)

  // {

  // c5=Color.FromArgb(245,245,245);

  // //c2=Color.FromArgb(192,192,192);

  // c2=Color.FromArgb(180,175,190);

  // }

  // Brush b = new System.Drawing.Drawing2D.LinearGradientBrush

  // (ClientRectangle, c5, c2, LinearGradientMode.Vertical);


  //pevent.Graphics .DrawRectangle(new Pen(Color.Transparent,2),this.ClientRectangle);

  pevent.Graphics .Clear(Color.Wheat );

  //base.OnPaintBackground (pevent);


 }  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值