Exemplo n.º 1
0
        void border_DragEnded(object sender, EventArgs e)
        {
            border_Moved(sender, e);


            Controls.Remove(dragWindowBorder);
            dragWindowBorder.Dispose();

            dragWindowBorder = null;
        }
Exemplo n.º 2
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (dragWindowBorder == null && borderStyle == WindowBorderStyle.Normal)
            {
                Rectangle bounding = GetBounding();

                int leftDist   = e.CursorPosition.X - bounding.Left;
                int topDist    = e.CursorPosition.Y - bounding.Top;
                int rightDist  = bounding.Right - e.CursorPosition.X;
                int bottomDist = bounding.Bottom - e.CursorPosition.Y;


                //Check for borders to drag;

                Border border = Border.None;
                if (leftDist > 0 && leftDist < GetDragBorderSize(Border.Left))
                {
                    border |= Border.Left;
                }
                if (topDist > 0 && topDist < GetDragBorderSize(Border.Top))
                {
                    border |= Border.Top;
                }
                if (rightDist > 0 && rightDist < GetDragBorderSize(Border.Right))
                {
                    border |= Border.Right;
                }
                if (bottomDist > 0 && bottomDist < GetDragBorderSize(Border.Bottom))
                {
                    border |= Border.Bottom;
                }


                if (border != Border.None)
                {
                    Vector2 pos = new Vector2((bounding.Left + bounding.Right) / 2, (bounding.Top + bounding.Bottom) / 2);
                    if ((border & Border.Left) > 0)
                    {
                        pos.X = bounding.Left;
                    }
                    if ((border & Border.Right) > 0)
                    {
                        pos.X = bounding.Right;
                    }
                    if ((border & Border.Top) > 0)
                    {
                        pos.Y = bounding.Top;
                    }
                    if ((border & Border.Bottom) > 0)
                    {
                        pos.Y = bounding.Bottom;
                    }

                    GuiWindowBorder windowBorder = new GuiWindowBorder(this, border);
                    dragWindowBorder          = windowBorder;
                    dragWindowBorder.Position = pos;
                    dragWindowBorder.Size     = new Vector2(1, 1);
                    Controls.Add(windowBorder);

                    windowBorder.Moved     += new EventHandler <EventArgs>(border_Moved);
                    windowBorder.DragEnded += new EventHandler <EventArgs>(border_DragEnded);

                    dragWindowBorder.StartDrag();
                }
                else
                {
                    StartDrag();
                }
            }
            else
            {
                //Dragging the border, impossible?
            }
        }