本文整理汇总了C#中System.Windows.Rect.Offset方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Offset方法的具体用法?C# Rect.Offset怎么用?C# Rect.Offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Rect
的用法示例。
在下文中一共展示了Rect.Offset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
Rect rect = new Rect(startPoint, endPoint);
rect.Offset(-0.5d, -0.5d);
drawingContext.DrawRectangle(fill, stroke, rect);
}
示例2: OnRender
protected override void OnRender( DrawingContext dc )
{
Rect rect;
if ( myLocation == DropLocation.InPlace )
{
rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight ) );
rect.Inflate( -1, -1 );
}
else
{
rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight * 0.2 ) );
if ( myLocation == DropLocation.Before )
{
rect.Offset( 0, -myOwner.ActualHeight * 0.1 );
}
else if ( myLocation == DropLocation.After )
{
rect.Offset( 0, myOwner.ActualHeight * 0.9 );
}
rect.Inflate( -1, 0 );
}
var brush = new SolidColorBrush( Colors.LightSkyBlue );
brush.Opacity = 0.5;
var pen = new Pen( new SolidColorBrush( Colors.White ), 1 );
dc.DrawRectangle( brush, pen, rect );
}
示例3: 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;
}
示例4: OffsetRect
public static Rect OffsetRect(Rect rect, Vector offset, double scale)
{
Rect result = new Rect(rect.TopLeft, rect.BottomRight);
result.Offset(offset);
result.Scale(scale, scale);
return result;
}
示例5: ArrangeOverride
// Methods
protected override Size ArrangeOverride(Size finalSize)
{
if (base.Children.Count < 2)
{
return base.ArrangeOverride(finalSize);
}
bool flag = false;
double num = 0.0;
if (((base.Children[0].DesiredSize.Height + base.Children[1].DesiredSize.Height) > finalSize.Height) || ((base.Children[0].DesiredSize.Width + base.Children[1].DesiredSize.Width) < finalSize.Width))
{
flag = true;
num = Math.Max(base.Children[0].DesiredSize.Height, base.Children[1].DesiredSize.Height);
}
else
{
flag = false;
num = base.Children[0].DesiredSize.Height + base.Children[1].DesiredSize.Height;
}
int num2 = 2;
for (int i = 2; i < base.Children.Count; i++)
{
if ((num + base.Children[i].DesiredSize.Height) > finalSize.Height)
{
break;
}
num2 = i + 1;
num += base.Children[i].DesiredSize.Height;
}
Rect finalRect = new Rect(0.0, (finalSize.Height - num) / 2.0, finalSize.Width, 0.0);
if (flag)
{
double num4 = Math.Max(base.Children[0].DesiredSize.Height, base.Children[1].DesiredSize.Height);
finalRect.Width = Math.Min(base.Children[0].DesiredSize.Width, finalSize.Width);
finalRect.Height = num4;
base.Children[0].Arrange(finalRect);
finalRect.X = base.Children[0].DesiredSize.Width;
finalRect.Width = Math.Max((double)0.0, (double)(finalSize.Width - base.Children[0].DesiredSize.Width));
base.Children[1].Arrange(finalRect);
finalRect.X = 0.0;
finalRect.Y += num4;
finalRect.Width = finalSize.Width;
}
for (int j = flag ? 2 : 0; j < num2; j++)
{
finalRect.Height = base.Children[j].DesiredSize.Height;
base.Children[j].Arrange(finalRect);
finalRect.Offset(0.0, finalRect.Height);
}
finalRect.Height = 0.0;
for (int k = num2; k < base.Children.Count; k++)
{
base.Children[k].Arrange(finalRect);
}
return finalSize;
}
示例6: ArrangeOverride
/// <summary>
/// LinearPanel computes a position for each of its children taking into account their
/// </summary>
/// <param name="arrangeSize">Size that LinearPanel will assume to position children.</param>
protected override Size ArrangeOverride(Size arrangeSize)
{
var arc = Arc.Fill(arrangeSize, this.MinAngle, this.MaxAngle, this.IsDirectionReversed);
var rotateTransform = new RotateTransform(0, arc.Centre.X, arc.Centre.Y);
foreach (UIElement child in this.InternalChildren)
{
if (child == null)
{
continue;
}
Point ps;
Point pe;
double start = GetStart(child);
double end = GetEnd(child);
if (double.IsNaN(start) || double.IsNaN(end))
{
double center = GetAtValue(child);
if (!double.IsNaN(center))
{
var angle = TickHelper.ToAngle(center, this.Minimum, this.Maximum, arc);
var p1 = arc.GetPoint(angle);
var rect = new Rect(child.DesiredSize);
rect.Offset(new Vector(p1.X, p1.Y));
child.Arrange(rect);
}
}
else
{
ps = arc.GetPoint(start);
pe = arc.GetPoint(end);
child.Arrange(new Rect(ps, pe));
}
}
return arrangeSize;
}
示例7: UpdateZoomRect
private void UpdateZoomRect(Point zoomEndPoint) {
Rect output = Viewport.Output;
Rect tmpZoomRect = new Rect(zoomStartPoint, zoomEndPoint);
tmpZoomRect = Rect.Intersect(tmpZoomRect, output);
shouldKeepRatioWhileZooming = IsShiftPressed();
if (shouldKeepRatioWhileZooming) {
double currZoomRatio = tmpZoomRect.Width / tmpZoomRect.Height;
double zoomRatio = output.Width / output.Height;
if (currZoomRatio < zoomRatio) {
double oldHeight = tmpZoomRect.Height;
double height = tmpZoomRect.Width / zoomRatio;
tmpZoomRect.Height = height;
if (!tmpZoomRect.Contains(zoomStartPoint)) {
tmpZoomRect.Offset(0, oldHeight - height);
}
}
else {
double oldWidth = tmpZoomRect.Width;
double width = tmpZoomRect.Height * zoomRatio;
tmpZoomRect.Width = width;
if (!tmpZoomRect.Contains(zoomStartPoint)) {
tmpZoomRect.Offset(oldWidth - width, 0);
}
}
}
zoomRect = tmpZoomRect;
UpdateSelectionAdorner();
}
示例8: Overlap_Delegate
private static void Overlap_Delegate()
{
int i = 0;
Canvas _mainCanvas = (Canvas)delegate_Data[i++];
UIElement obj1 = (UIElement)delegate_Data[i++];
Rect rect1 = new Rect(obj1.RenderSize);
rect1.Offset(VisualTreeHelper.GetOffset(obj1));
if (obj1.GetType() == typeof(Ellipse))
{
EllipseGeometry geometry = new EllipseGeometry(rect1);
HitTestResults.Clear();
VisualTreeHelper.HitTest(_mainCanvas, new HitTestFilterCallback(_HitTestFilterGeometry), new HitTestResultCallback(_HitTestResultGeometry), new GeometryHitTestParameters(geometry));
}
else
{
RectangleGeometry geometry = new RectangleGeometry(rect1);
HitTestResults.Clear();
VisualTreeHelper.HitTest(_mainCanvas, new HitTestFilterCallback(_HitTestFilterGeometry), new HitTestResultCallback(_HitTestResultGeometry), new GeometryHitTestParameters(geometry));
}
}
示例9: OverlapBox
/// <summary>
/// Checks for shape overlap of bounding boxes (collision detection).
/// </summary>
/// <param name="shape1">
/// The first shape name.
/// </param>
/// <param name="shape2">
/// The second shape name.
/// </param>
/// <returns>
/// "True" or "False".
/// </returns>
public static Primitive OverlapBox(Primitive shape1, Primitive shape2)
{
UIElement obj1, obj2;
try
{
if (!_objectsMap.TryGetValue((string)shape1, out obj1))
{
Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape1);
return "False";
}
if (!_objectsMap.TryGetValue((string)shape2, out obj2))
{
Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape2);
return "False";
}
Rect rect1 = new Rect(obj1.RenderSize);
Rect rect2 = new Rect(obj2.RenderSize);
rect1.Offset(VisualTreeHelper.GetOffset(obj1));
rect2.Offset(VisualTreeHelper.GetOffset(obj2));
return rect1.IntersectsWith(rect2) ? "True" : "False";
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return "False";
}
}
示例10: OnRender
/// <summary>
/// Draw the connector lines at a lower level (OnRender) instead
/// of creating visual tree objects.
/// </summary>
protected override void OnRender(DrawingContext drawingContext)
{
#if DEBUG
if (displayBorder)
{
// Draws borders around the rows and groups.
foreach (DiagramRow row in rows)
{
// Display row border.
Rect bounds = new Rect(row.Location, row.DesiredSize);
drawingContext.DrawRectangle(null, new Pen(Brushes.DarkKhaki, 1), bounds);
foreach (DiagramGroup group in row.Groups)
{
// Display group border.
bounds = new Rect(group.Location, group.DesiredSize);
bounds.Offset(row.Location.X, row.Location.Y);
bounds.Inflate(-1, -1);
drawingContext.DrawRectangle(null, new Pen(Brushes.Gray, 1), bounds);
}
}
}
#endif
// Draw child connectors first, so marriage information appears on top.
foreach (DiagramConnector connector in logic.Connections)
{
if (connector.IsChildConnector)
connector.Draw(drawingContext);
}
// Draw all other non-child connectors.
foreach (DiagramConnector connector in logic.Connections)
{
if (!connector.IsChildConnector)
connector.Draw(drawingContext);
}
}
示例11: TS_MaskOutParentRect
/// -------------------------------------------------------------------
/// <summary>
/// Remove any point where the logicla element falls outside of
/// the boundaries of the parent containing control.
/// </summary>
/// -------------------------------------------------------------------
void TS_MaskOutParentRect(AutomationElement element, ref Drawing.Bitmap bm)
{
Rect leRect = element.Current.BoundingRectangle;
Rect parentRect = ControlParent(element).Current.BoundingRectangle;
// Cut it at the edge of the screen
parentRect = new Rect(parentRect.Left < 0 ? 0 : parentRect.Left, parentRect.Top < 0 ? 0 : parentRect.Top, parentRect.Right - parentRect.Left, parentRect.Bottom - parentRect.Top);
leRect = new Rect(leRect.Left < 0 ? 0 : leRect.Left, leRect.Top < 0 ? 0 : leRect.Top, leRect.Right - leRect.Left, leRect.Bottom - leRect.Top);
// Offset it since the origin of the bitmap is 0,0
parentRect.Offset(leRect.X, leRect.Y);
Rect outsideRect;
Drawing.Brush brush = new Drawing.SolidBrush(m_maskColor);
Drawing.Graphics g = Drawing.Graphics.FromImage(bm);
// Is the element wholy within the parent, just return...most cases
if (parentRect.Contains(leRect))
{
Comment("Element is not cliped by the parent");
m_TestStep++;
return;
}
// TODO: Get rid of the new Rect and just go new RectangleF
// Extents out the top
outsideRect = new Rect(leRect.Left, leRect.Top, leRect.Right, parentRect.Top);
g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));
// Extends out the right
outsideRect = new Rect(parentRect.Right, leRect.Top, leRect.Bottom, leRect.Right);
g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));
// Extends out the left
outsideRect = new Rect(leRect.Left, leRect.Top, parentRect.Left, leRect.Bottom);
g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));
// Extends out the bottom
outsideRect = new Rect(leRect.Left, parentRect.Bottom, leRect.Right, leRect.Bottom);
g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));
brush.Dispose();
Comment("Element is cliped by the parent and it's rectangle has been removed from the element's displayed rectangle");
m_TestStep++;
}
示例12: GetFormattedTextSize
GetFormattedTextBounds
(
FormattedText formattedText,
Point origin
)
{
Debug.Assert(formattedText != null);
Double dTextBottom =
formattedText.Height + formattedText.OverhangAfter;
Double dTextTop = dTextBottom - formattedText.Extent;
Size oSize = GetFormattedTextSize(formattedText);
Rect oBounds = new Rect(formattedText.OverhangLeading, dTextTop,
oSize.Width, oSize.Height);
oBounds.Offset(origin.X, origin.Y);
return (oBounds);
}
示例13: _LegacyInitializeCaptionButtonLocation
private void _LegacyInitializeCaptionButtonLocation()
{
// This calculation isn't quite right, but it's pretty close.
// I expect this is good enough for the scenarios where this is expected to be used.
int captionX = NativeMethods.GetSystemMetrics(SM.CXSIZE);
int captionY = NativeMethods.GetSystemMetrics(SM.CYSIZE);
int frameX = NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CXEDGE);
int frameY = NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CYEDGE);
Rect deviceCaptionLocation = new Rect(0.0, 0.0, (captionX * 3), captionY);
deviceCaptionLocation.Offset(-frameX - deviceCaptionLocation.Width, frameY);
Rect logicalCaptionLocation = DpiHelper.DeviceRectToLogical(deviceCaptionLocation);
WindowCaptionButtonsLocation = logicalCaptionLocation;
}
示例14: OnRender
protected override void OnRender(DrawingContext dc)
{
//warning : много хаков!
if (_diagram == null)
return;
Rect actualViewport = new Rect(0, 0, ActualWidth, ActualHeight);
dc.DrawRectangle(Brushes.White, null, actualViewport);
Rect boundaries = _diagram.Boundaries;
Rect viewport = _diagram.Viewport;
double scale;
double scaleX = actualViewport.Width / boundaries.Width;
double scaleY = actualViewport.Height / boundaries.Height;
scale = scaleX > scaleY ? scaleY : scaleX;
//прямоугольник с элементами
Rect viewerBoundaries = new Rect(0, 0, boundaries.Width * scale, boundaries.Height * scale);
dc.DrawRectangle(Brushes.White, GlobalData.BorderPen, viewerBoundaries);
//вьюпорт
Vector offset = new Vector(-boundaries.Left, -boundaries.Top);
Rect viewerViewport = new Rect(viewport.TopLeft, viewport.BottomRight);
viewerViewport.Offset(offset.X , offset.Y);
viewerViewport.Scale(scale, scale);
//пересекаем
RectangleGeometry geometryBoundaries = new RectangleGeometry(viewerBoundaries);
RectangleGeometry geometryViewport = new RectangleGeometry(viewerViewport);
CombinedGeometry geometryCombined = new CombinedGeometry(GeometryCombineMode.Exclude,
geometryBoundaries, geometryViewport);
SolidColorBrush brush = new SolidColorBrush(Colors.LightGray);
dc.PushOpacity(0.3);
dc.DrawGeometry(brush, null, geometryCombined);
dc.Pop();
dc.PushTransform(new ScaleTransform(scale, scale));
dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
_diagram.DrawItems(dc);
dc.Pop();
dc.Pop();
}
示例15: _CreateVisualChildren
/// <summary>
/// Create Gant TimeLine ranges.
/// </summary>
protected override Size _CreateVisualChildren(Size dimension, double rangeWidth, int rangeStepInHour)
{
Rect boundingRect = new Rect();
// Calculate range boundbox.
Size itemSize = new Size(rangeWidth, dimension.Height);
Rect itemRect = new Rect(new Point(0, 0), itemSize);
DateTime currentHour;
// Define start hour: "0" if _startDate in MaxValue
if (_startHour.Date == DateTime.MaxValue.Date)
currentHour = DateTime.MinValue;
else
currentHour = _startHour;
int current = 0;
while (current < (int)_duration)
{
// Create TimeLine range.
DrawingVisual visualItem = _CreateVisualItem(currentHour, rangeStepInHour, itemRect);
_children.Add(visualItem);
boundingRect.Union(visualItem.ContentBounds);
// Relocate for next element.
itemRect.Offset(rangeWidth, 0);
currentHour = currentHour.AddHours(rangeStepInHour);
current += rangeStepInHour;
}
return boundingRect.Size;
}