c#下重写BUTTON控件.doc_第1页
c#下重写BUTTON控件.doc_第2页
c#下重写BUTTON控件.doc_第3页
c#下重写BUTTON控件.doc_第4页
c#下重写BUTTON控件.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

c#下重写BUTTON控件XPButton.cs代码using System;using System.Windows;using System.Drawing;using System.Drawing.Drawing2D;using System.Windows .Forms ;namespace XPCtrl/ / XPButton 的摘要说明。/ public class XPButton:System.Windows.Forms.Buttonprivate 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 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);/System.Drawing.Region=new Region(int offsetwidth=this.Width/50;Point points=new Point8;points0.X=offsetwidth;points0.Y=0;points1.X=this.Width-offsetwidth;points1.Y=0;points2.X=this.Width;points2.Y=offsetwidth;points3.X=this.Width;points3.Y=this.Height-offsetwidth;points4.X=this.Width-offsetwidth;points4.Y=this.Height;points5.X=offsetwidth;points5.Y=this.Height;points6.X=0;points6.Y=this.Height-offsetwidth;points7.X=0;points7.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 Point8;points10.X=offsetwidth1;points10.Y=2;points11.X=this.Width-offsetwidth1;points11.Y=2;points12.X=this.Width-1;points12.Y=offsetwidth1;points13.X=this.Width-1;points13.Y=this.Height-offsetwidth1;points14.X=this.Width-offsetwidth1;points14.Y=this.Height-1;points15.X=1;points15.Y=this.Height-1;points16.X=2;points16.Y=this.Height-offsetwidth1;points17.X=2;points17.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,points10,points11);e.Graphics.DrawLine(p,points11,points12);e.Graphics.DrawLine(p,points12,points13);e.Graphics.DrawLine(p,points13,points14);e.Graphics.DrawLine(p,points14,points15);e.Graphics.DrawLine(p,points15,points16);e.Graphics.DrawLine(p1,points16,points17);e.Graphics.DrawLine(p1,points17,points10);e.Graphics.DrawPolygon(new Pen(Color.DarkBlue,2),points);/e.Graphics.DrawLine(new Pen(Color.DarkBlue,2),new Point(0,0),new Point(this.Width,0);/e.Graphics.DrawLine(new Pen(Color.DarkBlue,2),new Point(0,0),new Point(0,this.Height);/e.Graphics.DrawLine(new Pen(Color.DarkBlue,2),new Point(this.Width,this.Height),new Point(this.Width,0);/e.Graphics.DrawLine(new Pen(Color.DarkBlue,2),new Point(this.Width,this.Height),new Point(0,this.Height);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.C

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论