zoukankan      html  css  js  c++  java
  • MatrixTransform 控件拖动边界检测

    原项目演示地址 http://www.youpvp.com/misc/adorners.html
    但那个项目没有加上边界检测,要加上边界检测,只需修改方法 adorned_MouseMove

    void adorned_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDragging)
        {
            Point pt = e.GetPosition(null);//返回鼠标在整个 Silverlight 插件内容区域内的坐标位置。
            Point ee = e.GetPosition(this);//返回鼠标在当前控件内容区域内的坐标位置。
            Matrix mx = (current.RenderTransform as MatrixTransform).Matrix;
            double Height = (double)this.Parent.GetValue(ActualHeightProperty);//获取 Silverlight 插件的呈现区域的高度
            double Width = (double)this.Parent.GetValue(ActualWidthProperty);//获取 Silverlight 插件的呈现区域的宽度
            double MinX = Math.Max(ee.X, pt.X);
            double MinY = Math.Max(ee.Y, pt.Y);
            double MaxX = current.ActualWidth - ee.X + pt.X;//当前控件右边的位置
            double MaxY = current.ActualHeight - ee.Y + pt.Y;//当前控件下边的位置
    
            if (MaxX < Width)
            {
                mx.OffsetX += MinX - dragAnchor.X;
            }
            else
            {
                mx.OffsetX += -1;
            }
            if (MaxY < Height)
            {
                mx.OffsetY += MinY - dragAnchor.Y;
            }
            else
            {
                mx.OffsetY += -1;
            }
    
            //mx.OffsetX += pt.X - dragAnchor.X;
            //mx.OffsetY += pt.Y - dragAnchor.Y;
            current.RenderTransform = new MatrixTransform() { Matrix = mx };
            dragAnchor = pt;
        }
    }
    
  • 相关阅读:
    「CH6801」棋盘覆盖
    「POJ3613」Cow Relays
    「Luogu4556」Vani有约会-雨天的尾巴
    The Proof of Fibonacci GCD
    Ubuntu flatabulous 主题
    CSP-S 2019 复赛游记
    「Luogu1402」酒店之王
    HDU/5499/模拟
    cfedu/A/求和
    HDU<1372>/bfs
  • 原文地址:https://www.cnblogs.com/geass/p/2026519.html
Copyright © 2011-2022 走看看