標籤:oid arc 使用者 graphics turn ase rri hang protected
以前項目自己寫的 ,一個模仿蘋果AppStore 下載進度條的winfrom使用者控制項,GDI繪製。效果
1 using System.Drawing; 2 using System.Windows.Forms; 3 using System.ComponentModel; 4 namespace test 5 { 6 public class CircleProgressBar : Control 7 { 8 float _progress = 0F; 9 float _Wpen = 1;10 float _Npen = 5;11 float _Fwidth = 10;12 [Description("進度條顏色")]13 public Color CircleColor14 {15 get;16 set;17 }18 [Description("外圈粗度")]19 public float WpenThin20 {21 get { return _Wpen; }22 set { _Wpen = value; }23 }24 [Description("內圈粗度")]25 public float NpenThin26 {27 get { return _Npen; }28 set { _Npen = value; }29 }30 [Description("內心方形邊長")]31 public float Fwitdh32 {33 get { return _Fwidth; }34 set { _Fwidth = value; }35 }36 public void PaintProgress(PaintEventArgs e)37 {38 float x = this.Width / 2;39 float y = this.Height / 2;//圓心座標40 float Wr = x - WpenThin / 2;//外圈半徑41 float Nr = x - NpenThin / 2;//內圈半徑42 int Wx = (int)(x - Wr);43 int Wy = (int)(y - Wr);//外圈起始座標44 int Nx = (int)(x - Nr);45 int Ny = (int)(y - Nr);//外圈起始座標46 int Fy = (int)(y - Fwitdh/2);47 int Fx = (int)(x - Fwitdh/2);// 內心方形座標48 Graphics dc = this.CreateGraphics();49 dc.Clear(this.BackColor);50 Pen Wpen = new Pen(CircleColor, WpenThin);51 Pen Npen = new Pen(CircleColor, NpenThin);52 Brush Fbrush = new SolidBrush(CircleColor);53 dc.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;54 float startAngle = -90;55 float sweepAngle = Progress / 100 * 360;//起始角度56 Rectangle Wrec = new Rectangle(Wx, Wy, 2 * (int)Wr, 2 * (int)Wr);57 Rectangle Nrec = new Rectangle(Nx, Ny, 2 * (int)Nr, 2 * (int)Nr);58 Rectangle Frec = new Rectangle(Fx, Fy, (int)Fwitdh, (int)Fwitdh);59 dc.DrawEllipse(Wpen, Wrec);60 dc.FillRectangle(Fbrush, Frec);61 dc.DrawArc(Npen, Nrec, startAngle, sweepAngle);62 }63 public float Progress64 {65 get { return _progress; }66 set67 {68 if (_progress != value && value >= 0 && value <= 100)69 {70 _progress = value;71 OnProgressChanged();72 }73 }74 }75 protected virtual void OnProgressChanged()76 {77 this.Invalidate();78 }79 protected override void OnPaint(PaintEventArgs e)80 {81 PaintProgress(e);82 base.OnPaint(e);83 }84 }85 }
仿蘋果AppStore 下載進度條