本文整理汇总了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);
}