Пример #1
0
        public void StartLoading(ERollingBarStyle style = ERollingBarStyle.Default)
        {
            // 对当前界面复制快照图片
            loadingBack = new Bitmap(this.Width, this.Height);
            Graphics graphic = Graphics.FromImage(loadingBack);

            graphic.CopyFromScreen(new Point(this.Location.X, this.Location.Y + this.CaptionHeight), new Point(0, 0), new Size(this.Width, this.Height - this.CaptionHeight));
            graphic.Dispose();
            if (maskLayer == null)
            {
                maskLayer          = new Panel();
                maskLayer.Size     = new Size(this.Width, this.Height - this.CaptionHeight);
                maskLayer.Location = new Point(0, this.CaptionHeight + 1);
                this.Controls.Add(maskLayer);
                rollingBar             = new DRolling();
                rollingBar.Size        = new System.Drawing.Size(60, 60);
                rollingBar.Location    = new System.Drawing.Point((this.maskLayer.Width - 60) / 2, (this.maskLayer.Height - 60) / 2 - this.CaptionHeight);
                rollingBar.SliceColor  = Color.FromArgb(231, 76, 60);
                rollingBar.RadiusOut   = 38;
                rollingBar.SliceNumber = 12;
                rollingBar.Location    = new System.Drawing.Point((this.maskLayer.Width - 60) / 2, (this.maskLayer.Height - 60) / 2 - this.CaptionHeight);
                this.maskLayer.Controls.Add(rollingBar);
            }
            rollingBar.RollingStyle = style;
            rollingBar.RadiusIn     = style == ERollingBarStyle.Default ? 20 : 38;
            rollingBar.PenWidth     = style == ERollingBarStyle.Default ? 3 : 5;
            this.maskLayer.Visible  = true;
            this.maskLayer.BringToFront();
            this.maskLayer.BackgroundImage = loadingBack;
            this.rollingBar.Visible        = true;
            this.rollingBar.BringToFront();
            this.rollingBar.Start();
        }
Пример #2
0
        /// <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);
        }