HuronControl.RoundcornerForm()
功能:圓角窗口(WinForm,無邊框窗口最佳)。
該控件繼承自System.Windows.Forms
代碼:
public RoundcornerForm()
{
this.Paint += new PaintEventHandler(RoundcornerForm_Paint);
}
private void RoundcornerForm_Paint(object sender, PaintEventArgs e)
{
List<Point> list = new List<Point>();
int width = this.Width;
int height = this.Height;
//左上
list.Add(new Point(0, 5));
list.Add(new Point(1, 5));
list.Add(new Point(1, 3));
list.Add(new Point(2, 3));
list.Add(new Point(2, 2));
list.Add(new Point(3, 2));
list.Add(new Point(3, 1));
list.Add(new Point(5, 1));
list.Add(new Point(5, 0));
//右上
list.Add(new Point(width - 5, 0));
list.Add(new Point(width - 5, 1));
list.Add(new Point(width - 3, 1));
list.Add(new Point(width - 3, 2));
list.Add(new Point(width - 2, 2));
list.Add(new Point(width - 2, 3));
list.Add(new Point(width - 1, 3));
list.Add(new Point(width - 1, 5));
list.Add(new Point(width - 0, 5));
//右下
list.Add(new Point(width - 0, height - 5));
list.Add(new Point(width - 1, height - 5));
list.Add(new Point(width - 1, height - 3));
list.Add(new Point(width - 2, height - 3));
list.Add(new Point(width - 2, height - 2));
list.Add(new Point(width - 3, height - 2));
list.Add(new Point(width - 3, height - 1));
list.Add(new Point(width - 5, height - 1));
list.Add(new Point(width - 5, height - 0));
//左下
list.Add(new Point(5, height - 0));
list.Add(new Point(5, height - 1));
list.Add(new Point(3, height - 1));
list.Add(new Point(3, height - 2));
list.Add(new Point(2, height - 2));
list.Add(new Point(2, height - 3));
list.Add(new Point(1, height - 3));
list.Add(new Point(1, height - 5));
list.Add(new Point(0, height - 5));
Point[] points = list.ToArray();
GraphicsPath shape = new GraphicsPath();
shape.AddPolygon(points);
this.Region = new System.Drawing.Region(shape);
}
應用範圍推薦:載入中顯示窗口,桌面貼片
實例:
仿Apple半透明Loading控件
窗口構造
// WinForm 實例 frmFlag
private LoadingCircle loadingCircle = new HuronControl.LoadingCircle();
// loadingCircle
this.loadingCircle.BackColor = System.Drawing.Color.DimGray;
this.loadingCircle.InnerCircleRadius = 15;
this.loadingCircle.LineWidth = 3;
this.loadingCircle.Name = "loadingCircle";
this.loadingCircle.OutnerCircleRadius = 40;
this.loadingCircle.Speed = 100;
this.loadingCircle.SpokesMember = 15;
this.loadingCircle.ThemeColor = System.Drawing.Color.White;
// frmFlag
this.BackColor = System.Drawing.Color.DimGray;
this.Controls.Add(this.loadingCircle);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmFlag";
this.Opacity = 0.8D;
this.ShowIcon = false;
this.TopMost = true;
控制方法
int steps = 100; //總步數
int step = 0; //當前進度
//步進方式
//步進開始
loadingCircle.StartStep(steps);
//步進到...(建議配合線程或Timer使用)
loadingCircle.PerformStep(step);
//循環方式
loadingCircle1.StartMarquee();
注:若使用線程控制loadingCircle步進,需要使用委託,類似如下
this.BeginInvoke(new EventHandler(PerformStep));