コード例 #1
0
ファイル: Helpers.cs プロジェクト: kenaschmidt/Finance
        /// <summary>
        /// Sets a control location based on location and docking style of target control
        /// </summary>
        /// <param name="me"></param>
        /// <param name="target"></param>
        /// <param name="dockToSide"></param>
        /// <param name="buffer"></param>
        public static void DockTo(this Control me, Control target, ControlEdge dockToSide, int buffer = 0)
        {
            if (target == null)
            {
                return;
            }

            switch (dockToSide)
            {
            case ControlEdge.Left:
                me.Location = new Point((target.Left - me.Width) - buffer, target.Top);
                break;

            case ControlEdge.Right:
                me.Location = new Point(target.Right + buffer, target.Top);
                break;

            case ControlEdge.Top:
                me.Location = new Point(target.Left, (target.Top - me.Height) - buffer);
                break;

            case ControlEdge.Bottom:
                me.Location = new Point(target.Left, (target.Bottom + buffer));
                break;

            default:
                break;
            }
        }
コード例 #2
0
ファイル: Helpers.cs プロジェクト: kenaschmidt/Finance
        public static void SnapTo(this Form me, Form target, ControlEdge myEdge)
        {
            if (target == null)
            {
                return;
            }

            switch (myEdge)
            {
            case ControlEdge.Left:
                me.Location = new Point((target.Right), me.Location.Y);
                break;

            case ControlEdge.Right:
                me.Location = new Point((target.Left - me.Width), me.Location.Y);
                break;

            case ControlEdge.Top:
                me.Location = new Point(me.Location.X, target.Bottom);
                break;

            case ControlEdge.Bottom:
                me.Location = new Point(me.Location.X, target.Top - me.Height);
                break;

            default:
                break;
            }
        }
コード例 #3
0
        private void Size_MouseLeave(object sender, EventArgs e)
        {
            var c = (Control)sender;

            m_Edge        = ControlEdge.None;
            m_IsEdgeDrawn = false;
            c.Refresh();
        }
コード例 #4
0
        public ControlDesigner(Control ctl, DesignElement designType, ControlEdge resizeType = ControlEdge.All, string caption = null)
        {
            Dbg.Assert(ctl != null, "Control designer can't be  initialized without parent control");
            ProcessedControl = ctl;
            if (RealControl != null)
            {
                switch (RealControl.Dock)
                {
                case DockStyle.Top:
                    if ((resizeType & ControlEdge.Bottom) != 0)
                    {
                        ResizeEdges = ControlEdge.Bottom;
                    }
                    break;

                case DockStyle.Bottom:
                    if ((resizeType & ControlEdge.Top) != 0)
                    {
                        ResizeEdges = ControlEdge.Top;
                    }
                    break;

                case DockStyle.Left:
                    if ((resizeType & ControlEdge.Right) != 0)
                    {
                        ResizeEdges = ControlEdge.Right;
                    }
                    break;

                case DockStyle.Right:
                    if ((resizeType & ControlEdge.Left) != 0)
                    {
                        ResizeEdges = ControlEdge.Left;
                    }
                    break;

                case DockStyle.Fill:
                    ResizeEdges = ControlEdge.None;
                    break;

                default:
                    ResizeEdges = resizeType;
                    break;
                }
                if (RealControl.Dock != DockStyle.None)
                {
                    designType = ~DesignElement.Moving & designType;
                }
            }
            DesignType = designType;
            InitBehavior(Point.Empty, Size.Empty, caption);
        }
コード例 #5
0
        private bool IsCursorInsideResizeArea(object sender, MouseEventArgs e, out ControlEdge edge)
        {
            var c = sender as Control;

            if (c == null)
            {
                edge = ControlEdge.None;
                return(false);
            }
            if (e.X <= (EdgeWidth * 4) && e.Y <= (EdgeWidth * 4) && (ResizeEdges & ControlEdge.TopLeft) == ControlEdge.TopLeft) //top left corner
            {
                c.Cursor = Cursors.SizeNWSE;
                edge     = ControlEdge.TopLeft;
                return(true);
            }
            if (e.X > c.Width - (EdgeWidth * 4) && e.Y > c.Height - (EdgeWidth * 4) && (ResizeEdges & ControlEdge.RightBottom) == ControlEdge.RightBottom) //right bottom corner
            {
                c.Cursor = Cursors.SizeNWSE;
                edge     = ControlEdge.RightBottom;
                return(true);
            }
            if (e.X <= EdgeWidth && (ResizeEdges & ControlEdge.Left) > 0)//left edge
            {
                c.Cursor = Cursors.VSplit;
                edge     = ControlEdge.Left;
                return(true);
            }
            if ((e.X > c.Width - (EdgeWidth + 1)) && (ResizeEdges & ControlEdge.Right) > 0)// 'right edge
            {
                c.Cursor = Cursors.VSplit;
                edge     = ControlEdge.Right;
                return(true);
            }
            if (e.Y <= EdgeWidth && (ResizeEdges & ControlEdge.Top) > 0) // 'top edge
            {
                c.Cursor = Cursors.HSplit;
                edge     = ControlEdge.Top;
                return(true);
            }
            if ((e.Y > c.Height - (EdgeWidth + 1)) && (ResizeEdges & ControlEdge.Bottom) > 0)//bottom edge
            {
                c.Cursor = Cursors.HSplit;
                edge     = ControlEdge.Bottom;
                return(true);
            }
            c.Cursor = Cursors.Default;
            edge     = ControlEdge.None;
            return(false);
        }
コード例 #6
0
ファイル: Helpers.cs プロジェクト: kenaschmidt/Finance
        public static bool EdgesAreClose(this Form me, ControlEdge myEdge, Form other, int distance)
        {
            switch (myEdge)
            {
            case ControlEdge.Left:
                if (Math.Abs(me.Left - other.Right) <= distance &&
                    ((me.Top.IsBetween(other.Top, other.Bottom) || me.Bottom.IsBetween(other.Top, other.Bottom)) ||
                     other.Top.IsBetween(me.Top, me.Bottom) || other.Bottom.IsBetween(me.Top, me.Bottom)))
                {
                    return(true);
                }
                break;

            case ControlEdge.Right:
                if (Math.Abs(me.Right - other.Left) <= distance &&
                    ((me.Top.IsBetween(other.Top, other.Bottom) || me.Bottom.IsBetween(other.Top, other.Bottom)) ||
                     other.Top.IsBetween(me.Top, me.Bottom) || other.Bottom.IsBetween(me.Top, me.Bottom)))
                {
                    return(true);
                }
                break;

            case ControlEdge.Top:
                if (Math.Abs(me.Top - other.Bottom) <= distance &&
                    ((me.Left.IsBetween(other.Left, other.Right) || me.Right.IsBetween(other.Left, other.Right)) ||
                     other.Left.IsBetween(me.Left, me.Right) || other.Right.IsBetween(me.Left, me.Right)))
                {
                    return(true);
                }
                break;

            case ControlEdge.Bottom:
                if (Math.Abs(me.Bottom - other.Top) <= distance &&
                    ((me.Left.IsBetween(other.Left, other.Right) || me.Right.IsBetween(other.Left, other.Right)) ||
                     other.Left.IsBetween(me.Left, me.Right) || other.Right.IsBetween(me.Left, me.Right)))
                {
                    return(true);
                }
                break;

            default:
                break;
            }
            return(false);
        }
コード例 #7
0
ファイル: Helpers.cs プロジェクト: kenaschmidt/Finance
        public static ControlEdge Opposite(this ControlEdge me)
        {
            switch (me)
            {
            case ControlEdge.None:
                return(ControlEdge.None);

            case ControlEdge.Left:
                return(ControlEdge.Right);

            case ControlEdge.Right:
                return(ControlEdge.Left);

            case ControlEdge.Top:
                return(ControlEdge.Bottom);

            case ControlEdge.Bottom:
                return(ControlEdge.Top);

            default:
                return(ControlEdge.None);
            }
        }