Exemplo n.º 1
0
 void _ResizeChangedMethod(object sender, ResizeEventArgs e)
 {
     if (null != ResizeChanged)
     {
         ResizeChanged(sender, e);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 移动事件处理方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void triggerPart_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.startMoving)
            {
                ResizeEventArgs args = new ResizeEventArgs();
                //if (null == ParentCtr)
                //{
                //    ParentCtr = resizePart.Parent as Panel;
                //}
                Point curMousePos = e.GetPosition(ParentCtr);//画布的位置
                args.CurPoint      = curMousePos;
                args.DragDirection = triggerPart.Location;
                double top    = (double)this.resizePart.GetValue(Canvas.TopProperty);
                double left   = (double)this.resizePart.GetValue(Canvas.LeftProperty);
                double xValue = curMousePos.X - this.prevMousePos.X;    //-->X轴坐标 水平
                double yValue = curMousePos.Y - this.prevMousePos.Y;    //-->Y轴坐标 垂直
                double Height = this.resizePart.Height;                 //-->高
                double Width  = this.resizePart.Width;                  //-->底

                switch (triggerPart.Location)
                {
                case AuchorLocation.右:
                    //-->xValue >0; y < 0;
                    //-->控件大小x变大,y变大
                    //-->控件的位置top变小,left不变
                    Width  += xValue;
                    Height -= yValue;
                    top    += yValue;
                    //top = (double)this.resizePart.GetValue(Canvas.TopProperty) + yValue;
                    //this.resizePart.SetValue(Canvas.TopProperty, top);
                    break;

                case AuchorLocation.中:
                    //-->控件x不变,y变大
                    //-->top变小,left不变
                    Height -= yValue;
                    top    += yValue;
                    //top = (double)this.resizePart.GetValue(Canvas.TopProperty) + yValue;
                    //this.resizePart.SetValue(Canvas.TopProperty, top);
                    break;

                case AuchorLocation.左:
                    //-->控件的坐标x变小、y变小,控件大小是增加 x+width、y+height
                    //--> xValue = 10 - 20 = -10;
                    Width  -= xValue;
                    Height -= yValue;
                    top    += yValue;
                    left   += xValue;
                    //top = (double)this.resizePart.GetValue(Canvas.TopProperty) + yValue;
                    //left = (double)this.resizePart.GetValue(Canvas.LeftProperty) + xValue;
                    //this.resizePart.SetValue(Canvas.TopProperty, top);
                    //this.resizePart.SetValue(Canvas.LeftProperty, left);
                    break;

                case AuchorLocation.右:
                    Width  += xValue;
                    Height += yValue;
                    break;

                case AuchorLocation.中:
                    Height += yValue;
                    break;

                case AuchorLocation.左:
                    Width  -= xValue;
                    Height += yValue;
                    left   += xValue;
                    //left = (double)this.resizePart.GetValue(Canvas.LeftProperty) + xValue;
                    //this.resizePart.SetValue(Canvas.LeftProperty, left);
                    break;

                case AuchorLocation.右中:
                    //-->X轴发生变化
                    Width += xValue;
                    break;

                case AuchorLocation.左中:
                    //-->X轴的值变大,宽变大或变小
                    Width -= xValue;
                    left  += xValue;
                    //left = (double)this.resizePart.GetValue(Canvas.LeftProperty) + xValue;
                    //this.resizePart.SetValue(Canvas.LeftProperty, left);
                    break;
                }
                //Width = (int)Width;
                //Height = (int)Height;
                if (Width > 16)
                {
                    this.resizePart.Width = Width;
                }
                else
                {
                    this.resizePart.Width = 16;
                }
                if (Height > 16)
                {
                    this.resizePart.Height = Height;
                }
                else
                {
                    this.resizePart.Height = 16;
                }
                //top = (int)top;
                //left = (int)left;
                this.resizePart.SetValue(Canvas.TopProperty, top);
                this.resizePart.SetValue(Canvas.LeftProperty, left);


                this.prevMousePos = curMousePos;
                _ResizeChangedMethod(this, null);
            }
        }