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));