Ejemplo n.º 1
0
        /// <summary>
        /// 在指定的容器下面弹出包含指定控件的层
        /// </summary>
        /// <param name="parent">容器</param>
        /// <param name="content">显示的内容</param>
        /// <param name="size">大小,为空则以显示控件大小为准</param>
        /// <returns></returns>
        public static ToolStripDropDown Show(Control parent, Control content, Size size, bool autoClose = false)
        {
            ToolStripControlHost host;
            ToolStripDropDown    dropDown;
            MPanel container;

            container             = new MPanel();
            content.Location      = new System.Drawing.Point(1, 1);
            container.BorderStyle = ButtonBorderStyle.Solid;
            container.BorderWidth = 1;
            container.BorderColor = System.Drawing.Color.LightGray;
            content.SizeChanged  += Content_SizeChanged;
            host = new ToolStripControlHost(container);
            container.Controls.Add(content);

            dropDown = new ToolStripDropDown();
            dropDown.Items.Add(host);
            dropDown.AutoClose = autoClose;

            host.Margin      = Padding.Empty;
            host.Padding     = Padding.Empty;
            host.AutoSize    = true;
            dropDown.Padding = Padding.Empty;

            //添加
            dropDown.Items.Add(host);
            if (size.IsEmpty)
            {
                size = new System.Drawing.Size(content.Width + 2, content.Height + 2);
            }

            dropDown.Size  = size;
            container.Size = size;
            content.Size   = size;

            dropDown.Show(parent, 0, parent.Height);

            return(dropDown);
        }
Ejemplo n.º 2
0
        /// <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;
                }
            }
        }
Ejemplo n.º 3
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);
        }