Пример #1
0
        // Called whenever thumb dragged (window resizing)
        void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            WindowThumb thumb = (WindowThumb)sender;

            // calculate mouse delta
            Point  position = PointToScreen(Mouse.GetPosition(_window));
            double deltaX   = position.X - _mouseStartPosition.X;
            double deltaY   = position.Y - _mouseStartPosition.Y;

            // horizontal resize
            if ((thumb.Position & Position.Left) == Position.Left)
            {
                this.SetWindowWidth(_windowStartSize.Width - deltaX);
                _window.Left = _windowStartPosition.X + deltaX;
            }
            else if ((thumb.Position & Position.Right) == Position.Right)
            {
                this.SetWindowWidth(_windowStartSize.Width + deltaX);
            }

            // vertical resize
            if ((thumb.Position & Position.Top) == Position.Top)
            {
                this.SetWindowHeight(_windowStartSize.Height - deltaY);
                _window.Top = _windowStartPosition.Y + deltaY;
            }
            else if ((thumb.Position & Position.Bottom) == Position.Bottom)
            {
                this.SetWindowHeight(_windowStartSize.Height + deltaY);
            }
        }
Пример #2
0
        // called when thumb drag started (window resize started)
        void Thumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            WindowThumb thumb = (WindowThumb)sender;

            // store settings of the window, will be used to resize and move the window
            _mouseStartPosition  = PointToScreen(Mouse.GetPosition(_window));
            _windowStartPosition = new Point(_window.Left, _window.Top);
            _windowStartSize     = new Size(_window.Width, _window.Height);
        }
        /// <summary>
        /// Auxilliary method for creating thumbs
        /// </summary>
        /// <param name="position">Thumb position in the window</param>
        /// <returns>Returns created WindowThumb</returns>
        WindowThumb CreateThumb(Position position, Cursor cursor)
        {
            WindowThumb thumb = new WindowThumb();
            thumb.Position = position;
            thumb.DragStarted += new DragStartedEventHandler(Thumb_DragStarted);
            thumb.DragDelta += new DragDeltaEventHandler(Thumb_DragDelta);
            thumb.Cursor = cursor;

            visualChildren.Add(thumb);

            return thumb;
        }
Пример #4
0
        /// <summary>
        /// Auxilliary method for creating thumbs
        /// </summary>
        /// <param name="position">Thumb position in the window</param>
        /// <returns>Returns created WindowThumb</returns>
        WindowThumb CreateThumb(Position position, Cursor cursor)
        {
            WindowThumb thumb = new WindowThumb();

            thumb.Position     = position;
            thumb.DragStarted += new DragStartedEventHandler(Thumb_DragStarted);
            thumb.DragDelta   += new DragDeltaEventHandler(Thumb_DragDelta);
            thumb.Cursor       = cursor;

            visualChildren.Add(thumb);

            return(thumb);
        }