Exemplo n.º 1
0
        /// <summary>
        /// DesignRectangle控件移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_MouseMove(object sender, MouseEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            if (isMouseCaptured)
            {
                isMoveByDesignRectangle = true;
                _maxLeft = cvsPanle.ActualWidth - item.Width;
                _maxTop  = cvsPanle.ActualHeight - item.Height;
                var    p       = e.GetPosition(cvsPanle);
                double deltaV  = p.Y - mouseVerticalPosition;
                double deltaH  = p.X - mouseHorizontalPosition;
                double newTop  = deltaV + (double)item.GetValue(Canvas.TopProperty);
                double newLeft = deltaH + (double)item.GetValue(Canvas.LeftProperty);
                newLeft = newLeft > _maxLeft ? _maxLeft : (newLeft < 0 ? 0 : newLeft);
                newTop  = newTop > _maxTop ? _maxTop : (newTop < 0 ? 0 : newTop);
                // Set new position of object.
                item.SetValue(Canvas.TopProperty, newTop);
                item.SetValue(Canvas.LeftProperty, newLeft);

                UpdateLineTopOrLeftPoint(new Point(newLeft + item.Width, newTop));

                if (null != _CurrentDesignCtrl)
                {
                    _CurrentDesignCtrl.SetValue(Canvas.TopProperty, newTop);
                    _CurrentDesignCtrl.SetValue(Canvas.LeftProperty, newLeft);
                    _CurrentDesignCtrl.Width  = item.Width;
                    _CurrentDesignCtrl.Height = item.Height;

                    //-->这里非常耗费资源。当鼠标弹起来的时候,更新会更好些。
                    //ControlModifyPropertyEventArgs ce = new ControlModifyPropertyEventArgs();
                    //ce.DictProperty.Add("Canvas.Top", newTop);
                    //ce.DictProperty.Add("Canvas.Left", newLeft);
                    //ce.DictProperty.Add("Height", dr.Height);
                    //ce.DictProperty.Add("Width", dr.Width);
                    //ce.ControlName = string.Format("{0}", Wrapper.GetPropertyValue(_CurrentDesignCtrl, "Name"));
                    //_ControlPositionMethod(this, ce);
                }
                //Update position global variables.
                mouseVerticalPosition   = e.GetPosition(cvsPanle).Y;
                mouseHorizontalPosition = e.GetPosition(cvsPanle).X;
            }
        }
Exemplo n.º 2
0
        void PageDesign_KeyDown(object sender, KeyEventArgs e)
        {
            if (null == _CurrentDesignCtrl)
            {
                return;
            }
            SetControlFocus(_CurrentDesignCtrl);
            double setp    = 1;
            double left    = (double)dr.GetValue(Canvas.LeftProperty);
            double top     = (double)dr.GetValue(Canvas.TopProperty);
            double newLeft = left;
            double newTop  = top;

            switch (e.Key)
            {
            case Key.Left:
                newLeft = left - setp;
                break;

            case Key.Right:
                newLeft = left + setp;
                break;

            case Key.Up:
                newTop = top - setp;
                break;

            case Key.Down:
                newTop = top + setp;
                break;

            case Key.Delete:
                DeleteCurrentSelectedControl();
                return;
            }
            dr.SetValue(Canvas.TopProperty, newTop);
            dr.SetValue(Canvas.LeftProperty, newLeft);
            this._CurrentDesignCtrl.SetValue(Canvas.TopProperty, newTop);
            this._CurrentDesignCtrl.SetValue(Canvas.LeftProperty, newLeft);
            isMouseCaptured = false;
        }