/// <summary> /// Works the complete. /// </summary> /// <param name="results">The results.</param> /// User:Ryan CreateTime:2012-8-5 16:23. private void WorkComplete(IAsyncResult results) { if (this.IsDisposed || !this.waitingLayer.Visible || !this.IsHandleCreated) { return; } if (this.waitingLayer.InvokeRequired) { try { this.Invoke(new Action <IAsyncResult>(this.WorkComplete), results); } catch { } } else { try { ((MethodInvoker)results.AsyncState).EndInvoke(results); } finally { this.Invoke(new MethodInvoker(() => { this.isWaiting = false; rolling.Stop(); this.Controls.Remove(waitingLayer); rolling = null; waitingInnerLayer = null; waitingLayer.Visible = false; waitingLayer = null; })); //waitingBox.Visible = false; } } }
/// <summary> /// 加载中,后台处理方法 /// </summary> /// <param name="method"></param> /// <param name="message"></param> /// <returns></returns> public bool Waiting(MethodInvoker method, ERollingBarStyle rollingStyle = ERollingBarStyle.Default, string message = "加载中,请稍后") { if (isWaiting) { return(false); } this.isWaiting = true; var captionHeight = this.Caption.Height; Size fontSize = Size.Empty; using (Graphics g = this.CreateGraphics()) { fontSize = Size.Ceiling(g.MeasureString(message, this.WaitingFont)); } Rectangle rect = new Rectangle(this.Padding.Left, this.Caption.Height, this.Width - this.Padding.Left - this.Padding.Right, this.Height - this.Caption.Height - this.Padding.Bottom); waitingLayer = new Panel(); waitingLayer.Size = rect.Size; waitingLayer.Location = rect.Location; waitingLayer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; this.waitingLayer.BackgroundImageLayout = ImageLayout.Stretch; this.Controls.Add(waitingLayer); rolling = new MRolling(); rolling.Size = new System.Drawing.Size(60, 60); rolling.Location = new Point(15, 10); rolling.SliceColor = Color.FromArgb(231, 76, 60); rolling.RadiusOut = 38; rolling.SliceNumber = 12; rolling.RollingStyle = rollingStyle; rolling.RadiusIn = rollingStyle == ERollingBarStyle.Default ? 20 : 38; rolling.PenWidth = rollingStyle == ERollingBarStyle.Default ? 3 : 5; waitingInnerLayer = new MPanel(); waitingInnerLayer.Radius = 10; waitingInnerLayer.BorderColor = Color.DarkGray; waitingInnerLayer.BorderWidth = 1; waitingInnerLayer.RadiusMode = RadiusMode.All; waitingInnerLayer.BackColor = Color.White; waitingInnerLayer.Size = new Size(rolling.Width + fontSize.Width + 42, rolling.Height + 22); waitingInnerLayer.Location = new Point((waitingLayer.Width - waitingInnerLayer.Width) / 2, (waitingLayer.Height - waitingInnerLayer.Height) / 2 - captionHeight); this.waitingInnerLayer.Controls.Add(rolling); var msgLabel = new Label(); msgLabel.Font = this.WaitingFont; msgLabel.Text = message; msgLabel.BackColor = Color.Transparent; msgLabel.AutoSize = true; msgLabel.Location = new Point(15 + rolling.Width + 10, (waitingInnerLayer.Height - fontSize.Height) / 2); this.waitingInnerLayer.Controls.Add(msgLabel); this.waitingLayer.Controls.Add(this.waitingInnerLayer); this.waitingLayer.BackgroundImage = CreateBacgroundImage(); this.Controls.Add(waitingLayer); this.waitingLayer.BringToFront(); this.rolling.Start(); IAsyncResult ar = method.BeginInvoke(this.WorkComplete, method); return(true); }