本文整理汇总了C#中System.Windows.Rect.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Contains方法的具体用法?C# Rect.Contains怎么用?C# Rect.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Rect
的用法示例。
在下文中一共展示了Rect.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContainsPoint
/// <summary>
/// Returns a value indicating whether a point is inside the bounding box of the element.
/// </summary>
/// <param name="element"></param>
/// <param name="pointRelativeToElement"></param>
/// <returns></returns>
public static bool ContainsPoint(this FrameworkElement element, Point pointRelativeToElement)
{
//TODO: Silverlight allows more complex geometries than Rectangle.
Rect rect = new Rect { X = 0, Y = 0, Width = element.ActualWidth, Height=element.ActualHeight };
return rect.Contains(pointRelativeToElement);
}
示例2: IsMouseOver
/// <summary>
/// Return wheter the mouse is over a control
/// </summary>
/// <param name="s"></param>
/// <param name="e"></param>
/// <returns>True if the mouse is over a control, false otherwise</returns>
internal static bool IsMouseOver(FrameworkElement s, System.Windows.Input.MouseEventArgs e)
{
Rect bounds = new Rect(0, 0, s.ActualWidth, s.ActualHeight);
if (bounds.Contains(e.GetPosition(s)))
return true;
return false;
}
示例3: LineIntersectsRect
public static bool LineIntersectsRect(Point p1, Point p2, Rect r)
{
return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
(r.Contains(p1) && r.Contains(p2));
}
示例4: IsInView
private static bool IsInView(FrameworkElement element, FrameworkElement container)
{
if (element == null || element.Visibility == Visibility.Collapsed) {
return false;
}
var bounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight));
var rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
return rect.Contains(new Point(bounds.X, bounds.Y)) || rect.Contains(new Point(bounds.X, bounds.Y + bounds.Height));
}
示例5: FitIntoScreen
private static bool FitIntoScreen(Rect workArea, Rect formSize, out Rect newFormSize)
{
var hasChanged = false;
newFormSize = formSize == Rect.Empty ? new Rect() : formSize;
if (!workArea.Contains(formSize)) {
// limiting size guarantees form fits into screen
newFormSize.Width = Math.Min(newFormSize.Width, workArea.Width);
newFormSize.Height = Math.Min(newFormSize.Height, workArea.Height);
if (newFormSize.Right > workArea.Right) {
newFormSize.Offset(workArea.Right - newFormSize.Right, 0);
hasChanged = true;
} else if (newFormSize.Left < workArea.Left) {
newFormSize.Offset(workArea.Left - newFormSize.Left, 0);
hasChanged = true;
}
if (newFormSize.Top < workArea.Top) {
newFormSize.Offset(0, workArea.Top - newFormSize.Top);
hasChanged = true;
} else if (newFormSize.Bottom > workArea.Bottom) {
newFormSize.Offset(0, workArea.Bottom - newFormSize.Bottom);
hasChanged = true;
}
}
return hasChanged;
}
示例6: detCursorSelection
public static bool detCursorSelection(Canvas rel, Point relPos, out UIElement result)
{
var list = new System.Collections.Generic.SortedList<int, UIElement>();
foreach (UIElement ue in rel.Children)
{
var ta = ue.TransformToAncestor(rel);
var p = ta.Transform(new Point(0, 0));
var r = new Rect(p, ue.RenderSize);
if (r.Contains(relPos))
try { list.Add(Canvas.GetZIndex(ue), ue); }
catch (Exception) { }
}
if (list.Count != 0)
{
var pr = list.Keys.Max();
result = list[pr];
return true;
}
else
{
result = null;
return false;
}
}
示例7: GetUnderlyingStateStationActivity
public StateStationActivityVm GetUnderlyingStateStationActivity(Point mouse)
{
var states = _parentWindowVm.States.Where(x => x.ShowDetails && x.Config != null);
foreach (var state in states)
{
TreeItemVm station;
if(_parentWindowVm.ShowAllMachines)
{
station = state.Config.ContentsList.SingleOrDefault(x => x.IsExpanded);
}
else
{
station = state.Config.ContentsList.SingleOrDefault(x => x.IsExpanded
&& (x.Containment as StationVm).StationMachines.Any(y => y.Machine.Id == this.ContentData.Id));
}
if (station == null) continue;
var activity = station.ContentsList.SingleOrDefault(x => x.IsExpanded) as StateStationActivityVm;
if (activity == null) continue;
if (activity.ContentsList.Any(ssa =>
ssa.Containment.Id == ContentData.Id
&& !ssa.IsDropIndicator)) continue;
Rect r = new Rect(state.Location.X, state.Location.Y, state.Width, state.Height);
if (r.Contains(mouse.X, mouse.Y))
return activity;
}
return null;
}
示例8: TickDragScroll
private void TickDragScroll(object sender, EventArgs e)
{
bool isDone = true;
if (this.IsLoaded)
{
Rect bounds = new Rect(RenderSize);
Point p = MouseUtilities.GetMousePosition(this);
if (bounds.Contains(p))
{
if (p.Y < s_dragMargin)
{
DragScroll(DragDirection.Up);
isDone = false;
}
else if (p.Y > RenderSize.Height - s_dragMargin)
{
DragScroll(DragDirection.Down);
isDone = false;
}
}
}
if (isDone)
{
CancelDrag();
}
}
示例9: OnManipulationDelta
protected override void OnManipulationDelta(System.Windows.Input.ManipulationDeltaEventArgs e)
{
Rectangle rectToMove = e.OriginalSource as Rectangle;
Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;
rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
e.ManipulationOrigin.X,
e.ManipulationOrigin.Y);
rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
e.DeltaManipulation.Scale.X,
e.ManipulationOrigin.X,
e.ManipulationOrigin.Y);
rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
e.DeltaManipulation.Translation.Y);
rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);
Rect containingRect =
new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
Rect shapeBounds =
rectToMove.RenderTransform.TransformBounds(
new Rect(rectToMove.RenderSize));
if (e.IsInertial && !containingRect.Contains(shapeBounds))
{
e.Complete();
}
e.Handled = true;
//base.OnManipulationDelta(e);
}
示例10: IsContained
public static bool IsContained(this Rect @this, Rect other, int tolerance)
{
other = new Rect(other.X - tolerance,
other.Y - tolerance,
other.Width + (tolerance * 2),
other.Height + (tolerance * 2));
return other.Contains(@this);
}
示例11: GetPointsInRect
public int[] GetPointsInRect(Rect rect)
{
var query = from i in Enumerable.Range(0, points.Count)
where rect.Contains(points[i])
select i;
return query.ToArray();
}
示例12: GetHitTestValue
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight)
{
var topLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight);
var topRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight);
return topLeft.Contains(point)
? HitTestValues.HTTOPLEFT
: topRight.Contains(point) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP;
}
示例13: GetCursor
public override Cursor GetCursor(Point point, double actualWidht, double actualHeight)
{
var topLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight);
var topRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight);
return topLeft.Contains(point)
? Cursors.SizeNWSE
: topRight.Contains(point) ? Cursors.SizeNESW : Cursors.SizeNS;
}
示例14: ContainsPoint
public static bool ContainsPoint(this UserControl uc,Point p)
{
double x = Canvas.GetLeft(uc);
double y = Canvas.GetTop(uc);
double width = uc.Width;
double height = uc.Height;
Rect r = new Rect(x, y, width, height);
return r.Contains(p);
}
示例15: GetHitTestValue
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight)
{
var bottomLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight);
var bottomRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight);
return bottomLeft.Contains(point)
? HitTestValues.HTBOTTOMLEFT
: bottomRight.Contains(point) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM;
}