当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.PointToScreen方法代码示例

本文整理汇总了C#中System.Windows.Shapes.Rectangle.PointToScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.PointToScreen方法的具体用法?C# Rectangle.PointToScreen怎么用?C# Rectangle.PointToScreen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Shapes.Rectangle的用法示例。


在下文中一共展示了Rectangle.PointToScreen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: withDragMarquee

 private void withDragMarquee(Action<Rect> doWithRect)
 {
     var canvas = new System.Windows.Controls.Canvas();
     var adornerLayer = AdornerLayer.GetAdornerLayer(this);
     var adorners = adornerLayer.GetAdorners(this);
     if (adorners != null)
         foreach (var a in adorners)
             if (a is UIAdorner && ((UIAdorner)a).contentType == typeof(System.Windows.Controls.Canvas))
                 return;
     var adorner = new UIAdorner(this, canvas);
     var marquee = new Rectangle { Fill = Brushes.Purple, Opacity = 0.4 };
     canvas.Background = new SolidColorBrush { Color = Colors.Wheat, Opacity = 0.1 };
     canvas.Children.Add(marquee);
     bool mouseDown = false;
     Point origin = new Point(-1, -1);
     Rect finalRect = new Rect();
     canvas.MouseDown += (sender, e) =>
     {
         var pos = e.GetPosition(this);
         var visPos = e.GetPosition(canvas);
         System.Windows.Controls.Canvas.SetLeft(marquee, visPos.X);
         System.Windows.Controls.Canvas.SetTop(marquee, visPos.Y);
         origin = pos;
         mouseDown = true;
     };
     canvas.MouseUp += (sender, e) =>
     {
         if (origin.X == -1 || origin.Y == -1) return;
         var pos = e.GetPosition(this);
         finalRect.X = (pos.X < origin.X) ? pos.X : origin.X;
         finalRect.Y = (pos.Y < origin.Y) ? pos.Y : origin.Y;
         finalRect.Height = Math.Abs(pos.Y - origin.Y);
         finalRect.Width = Math.Abs(pos.X - origin.X);
         mouseDown = false;
         if (!isPointNear(marquee.PointToScreen(finalRect.TopLeft), marquee.PointToScreen(finalRect.BottomRight), 10))
             doWithRect(finalRect);
         adornerLayer.Remove(adorner);
     };
     canvas.MouseMove += (sender, e) =>
     {
         if (!mouseDown || origin.X == -1 || origin.Y == -1) return;
         var pos = e.GetPosition(canvas);
         System.Windows.Controls.Canvas.SetLeft(marquee, Math.Min(origin.X, pos.X));
         System.Windows.Controls.Canvas.SetTop(marquee, Math.Min(origin.Y, pos.Y));
         marquee.Width = Math.Max(origin.X, pos.X) - Math.Min(origin.X, pos.X);
         marquee.Height = Math.Max(origin.Y, pos.Y) - Math.Min(origin.Y, pos.Y);
     };
     canvas.MouseLeave += (_sender, _args) =>
     {
         adornerLayer.Remove(adorner);
         Commands.EndGrabZoom.ExecuteAsync(null);
     };
     adornerLayer.Add(adorner);
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:54,代码来源:PresentationSpace.xaml.cs


注:本文中的System.Windows.Shapes.Rectangle.PointToScreen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。