Rect Struct

Definitie

Beschrijft de breedte, hoogte en locatie van een rechthoek.

public value class Rect : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.RectConverter))]
[System.Serializable]
public struct Rect : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.RectConverter))]
public struct Rect : IFormattable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.RectConverter))>]
[<System.Serializable>]
type Rect = struct
    interface IFormattable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.RectConverter))>]
type Rect = struct
    interface IFormattable
Public Structure Rect
Implements IFormattable
Overname
Kenmerken
Implementeringen

Voorbeelden

In het volgende voorbeeld ziet u hoe u een Rect structuur gebruikt om de dimensies en locatie van een rechthoek op te geven met behulp van XAML.

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SDKSample
{
    public partial class RectExample : Page
    {
        public RectExample()
        {   
            Path myPath1 = new Path();
            myPath1.Stroke = Brushes.Black;
            myPath1.StrokeThickness = 1;
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();
            mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255);
            myPath1.Fill = mySolidColorBrush;

            // Create the rectangle.
            // This RectangleGeometry specifies a rectangle that is 100 pixels high and
            // 150 wide. The left side of the rectangle is 10 pixels from the left of the 
            // Canvas and the top side of the rectangle is 100 pixels from the top of the Canvas.  
            // Note: You could alternatively use the Rect Constructor to create this:
            // Rect myRect1 = new Rect(10, 100, 150, 100);
            Rect myRect1 = new Rect();
            myRect1.X = 10;
            myRect1.Y = 100;
            myRect1.Width = 150;
            myRect1.Height = 100;
            RectangleGeometry myRectangleGeometry1 = new RectangleGeometry();
            myRectangleGeometry1.Rect = myRect1;

            GeometryGroup myGeometryGroup1 = new GeometryGroup();
            myGeometryGroup1.Children.Add(myRectangleGeometry1);

            myPath1.Data = myGeometryGroup1;

            Path myPath2 = new Path();
            myPath2.Stroke = Brushes.Black;
            myPath2.StrokeThickness = 1;
            myPath2.Fill = mySolidColorBrush;

            // Create the rectangle.
            // This Rect uses the Size property to specify a height of 50 and width
            // of 200. The Location property uses a Point value to determine the location of the
            // top-left corner of the rectangle.
            Rect myRect2 = new Rect();
            myRect2.Size = new Size(50, 200);
            myRect2.Location = new Point(300, 100);
            RectangleGeometry myRectangleGeometry2 = new RectangleGeometry();
            myRectangleGeometry2.Rect = myRect2;

            GeometryGroup myGeometryGroup2 = new GeometryGroup();
            myGeometryGroup2.Children.Add(myRectangleGeometry2);

            myPath2.Data = myGeometryGroup2;

            // Add path shape to the UI.
            Canvas myCanvas = new Canvas();
            myCanvas.Children.Add(myPath1);
            myCanvas.Children.Add(myPath2);
            this.Content = myCanvas;       
        }
    }
}

Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Shapes

Namespace SDKSample
    Partial Public Class RectExample
        Inherits Page
        Public Sub New()
            Dim myPath1 As New Path()
            myPath1.Stroke = Brushes.Black
            myPath1.StrokeThickness = 1
            Dim mySolidColorBrush As New SolidColorBrush()
            mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255)
            myPath1.Fill = mySolidColorBrush

            ' Create the rectangle.
            ' This RectangleGeometry specifies a rectangle that is 100 pixels high and
            ' 150 wide. The left side of the rectangle is 10 pixels from the left of the 
            ' Canvas and the top side of the rectangle is 100 pixels from the top of the Canvas.  
            ' Note: You could alternatively use the Rect Constructor to create this:
            ' Dim myRect1 As New Rect(10,100,150,100")
            Dim myRect1 As New Rect()
            myRect1.X = 10
            myRect1.Y = 100
            myRect1.Width = 150
            myRect1.Height = 100
            Dim myRectangleGeometry1 As New RectangleGeometry()
            myRectangleGeometry1.Rect = myRect1

            Dim myGeometryGroup1 As New GeometryGroup()
            myGeometryGroup1.Children.Add(myRectangleGeometry1)

            myPath1.Data = myGeometryGroup1

            Dim myPath2 As New Path()
            myPath2.Stroke = Brushes.Black
            myPath2.StrokeThickness = 1
            myPath2.Fill = mySolidColorBrush

            ' Create the rectangle.
            ' This Rect uses the Size property to specify a height of 50 and width
            ' of 200. The Location property uses a Point value to determine the location of the
            ' top-left corner of the rectangle.
            Dim myRect2 As New Rect()
            myRect2.Size = New Size(50, 200)
            myRect2.Location = New Point(300, 100)
            Dim myRectangleGeometry2 As New RectangleGeometry()
            myRectangleGeometry2.Rect = myRect2

            Dim myGeometryGroup2 As New GeometryGroup()
            myGeometryGroup2.Children.Add(myRectangleGeometry2)

            myPath2.Data = myGeometryGroup2

            ' Add path shape to the UI.
            Dim myCanvas As New Canvas()
            myCanvas.Children.Add(myPath1)
            myCanvas.Children.Add(myPath2)
            Me.Content = myCanvas
        End Sub
    End Class

End Namespace
<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Canvas>
    
    <!-- This rectangle demonstrates using the X, Y, Width, and Height properties
         of a Rect object. -->
    <Path Stroke="Black" StrokeThickness="1" Fill="LemonChiffon">
      <Path.Data>

        <!-- This RectangleGeometry specifies a rectangle that is 100 pixels high and
             150 wide. The left side of the rectangle is 10 pixels from the left of the 
             Canvas and the top side of the rectangle is 100 pixels from the top of the Canvas.  
             Note: An abbreviated syntax for creating an equivalent rectangle is:
             <RectangleGeometry Rect="10,100,150,100" /> -->
        <RectangleGeometry>
          <RectangleGeometry.Rect>
            <Rect X="10" Y="100" Width="150" Height="100" />
          </RectangleGeometry.Rect>
        </RectangleGeometry>
      </Path.Data>
    </Path>

    <!-- This rectangle demonstrates using the Size and Location properties of a Rect object. -->
    <Path Stroke="Black" StrokeThickness="1" Fill="LemonChiffon">
      <Path.Data>

        <!-- This RectangleGeometry uses the Size property to specify a height of 50 and width
             of 200. The Location property uses a Point value to determine the location of the
             top-left corner of the rectangle. /> -->
        <RectangleGeometry>
          <RectangleGeometry.Rect>
            <Rect Size="50,200" Location="300,100" />
          </RectangleGeometry.Rect>
        </RectangleGeometry>
      </Path.Data>
    </Path>
  </Canvas>
</Page>

In het volgende voorbeeld ziet u hoe u code gebruikt om een rechthoek te maken en deze toe te voegen aan de pagina. In het voorbeeld ziet u ook hoe u de grootte en coördinaatgegevens over de nieuwe rechthoek kunt vinden en de informatie in een TextBox onder de rechthoek kunt weergeven.

// Create a rectangle and add it to the page. Also,
// find size and coordinate information about this
// new rectangle and render information in a TextBox 
// below the rectangle.
private StackPanel createRectExample1()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. Set the Location property to an X coordinate of 10 and a
    // Y coordinate of 5. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    RectangleGeometry myRectangleGeometry = new RectangleGeometry();
    myRectangleGeometry.Rect = myRectangle;

    // This path is defined by the rectangle.
    Path myPath = new Path();
    myPath.Fill = Brushes.LemonChiffon;
    myPath.Stroke = Brushes.Black;
    myPath.StrokeThickness = 1;
    myPath.Data = myRectangleGeometry;

    //////////// Create string of rectangle property information /////////////
    // This string will contain all the size and coordinate property
    // information about the rectangle.
    /////////////////////////////////////////////////////////////////////////
    string rectInfo = "Rectangle Property Information: ";

    // Bottom property gets the y-axis value of the bottom of the rectangle. 
    // For this rectangle the value is 55.
    rectInfo = rectInfo + "Bottom: " + myRectangle.Bottom;

    // BottomLeft property gets the coordinates of the bottom left corner of the rectangle. 
    // For this rectangle the value is 10,55.
    rectInfo = rectInfo + "| BottomLeft: " + myRectangle.BottomLeft;

    // BottomRight property gets the coordinates of the bottom right corner of the rectangle. 
    // For this rectangle the value is 210,55.
    rectInfo = rectInfo + "| BottomRight: " + myRectangle.BottomRight;

    // Height property gets or sets the height of the rectangle. 
    // For this rectangle the value is 50.
    rectInfo = rectInfo + "| Height: " + myRectangle.Height;

    // Width property gets or sets the width of the rectangle. 
    // For this rectangle the value is 200.
    rectInfo = rectInfo + "| Width: " + myRectangle.Width;

    // Left property gets the x-axis position of the left side of the rectangle which is 
    // equivalent to getting the rectangle's X property. 
    // For this rectangle the value is 10.
    rectInfo = rectInfo + "| Left: " + myRectangle.Left;

    // Location property gets or sets the position of the rectangle's top-left corner.
    // For this rectangle the value is 10,5.
    rectInfo = rectInfo + "| Location: " + myRectangle.Location;

    // Right property gets the x-axis value of the right side of the rectangle. 
    // For this rectangle the value is 210.
    rectInfo = rectInfo + "| Right: " + myRectangle.Right;

    // Size property gets or sets the width and height of the rectangle.  
    // For this rectangle the value is 200,50.
    rectInfo = rectInfo + "| Size: " + myRectangle.Size;

    // Top property gets the y-axis position of the top of the rectangle which is 
    // equivalent to getting the rectangle's Y property.
    // For this rectangle the value is 5.
    rectInfo = rectInfo + "| Top: " + myRectangle.Top;

    // TopLeft property gets the position of the top-left corner of the rectangle, which 
    // is equivalent to (X, Y).   
    // For this rectangle the value is 10,5.
    rectInfo = rectInfo + "| TopLeft: " + myRectangle.TopLeft;

    // TopRight property gets the position of the top-left corner of the rectangle, which 
    // is equivalent to (X + Width, Y).   
    // For this rectangle the value is 210,5.
    rectInfo = rectInfo + "| TopRight: " + myRectangle.TopRight;

    // X property gets or sets the location of the rectangle's left side.  
    // For this rectangle the value is 10.
    rectInfo = rectInfo + "| X: " + myRectangle.X;

    // Y property gets or sets the location of the rectangle's top side.  
    // For this rectangle the value is 5.
    rectInfo = rectInfo + "| Y: " + myRectangle.Y;

    //////// End of creating string containing rectangle property information ////////

    // This StackPanel will contain the rectangle and TextBlock.
    StackPanel parentPanel = new StackPanel();

    // Add the rectangle path to the StackPanel. This will display the rectangle.
    parentPanel.Children.Add(myPath);

    // Add a TextBlock to display the rectangle's size and coordinate information.
    TextBlock myTextBlock = new TextBlock();
    myTextBlock.Text = rectInfo;
    parentPanel.Children.Add(myTextBlock);

    // Return the parent container to be displayed to the screen.
    return parentPanel;
}

Opmerkingen

XAML-kenmerkgebruik

<object property="x,y,width,height"/>

XAML-waarden

XSystem.Double

De x-coördinaatlocatie van de linkerkant van de rechthoek.

YSystem.Double

De y-coördinaatlocatie van de bovenzijde van de rechthoek.

BreedteSystem.Double

Een niet-negatieve waarde die de Width rechthoek vertegenwoordigt.

HoogteSystem.Double

Een niet-negatieve waarde die de Height rechthoek vertegenwoordigt.

Constructors

Name Description
Rect(Double, Double, Double, Double)

Initialiseert een nieuw exemplaar van de Rect structuur met de opgegeven x-coördinaat, y-coördinaat, breedte en hoogte.

Rect(Point, Point)

Initialiseert een nieuwe instantie van de Rect structuur die precies groot genoeg is om de twee opgegeven punten te bevatten.

Rect(Point, Size)

Initialiseert een nieuw exemplaar van de Rect structuur met de opgegeven locatie in de linkerbovenhoek en de opgegeven breedte en hoogte.

Rect(Point, Vector)

Initialiseert een nieuwe instantie van de Rect structuur die precies groot genoeg is om het opgegeven punt en de som van het opgegeven punt en de opgegeven vector te bevatten.

Rect(Size)

Initialiseert een nieuwe instantie van de Rect structuur met de opgegeven grootte en bevindt zich op (0,0).

Eigenschappen

Name Description
Bottom

Hiermee haalt u de waarde van de y-as op van de onderkant van de rechthoek.

BottomLeft

Hiermee haalt u de positie op van de linkerbenedenhoek van de rechthoek.

BottomRight

Hiermee haalt u de positie van de rechterbenedenhoek van de rechthoek op.

Empty

Hiermee wordt een speciale waarde opgehaald die een rechthoek vertegenwoordigt zonder positie of gebied.

Height

Hiermee haalt u de hoogte van de rechthoek op of stelt u deze in.

IsEmpty

Hiermee wordt een waarde opgehaald die aangeeft of de rechthoek de Empty rechthoek is.

Left

Hiermee haalt u de x-aswaarde van de linkerkant van de rechthoek op.

Location

Hiermee haalt u de positie van de linkerbovenhoek van de rechthoek op of stelt u deze in.

Right

Hiermee haalt u de x-aswaarde van de rechterkant van de rechthoek op.

Size

Hiermee haalt u de breedte en hoogte van de rechthoek op of stelt u deze in.

Top

Hiermee haalt u de positie van de y-as van de bovenkant van de rechthoek op.

TopLeft

Hiermee haalt u de positie op van de linkerbovenhoek van de rechthoek.

TopRight

Hiermee haalt u de positie op van de rechterbovenhoek van de rechthoek.

Width

Hiermee haalt u de breedte van de rechthoek op of stelt u deze in.

X

Hiermee wordt de x-aswaarde van de linkerkant van de rechthoek opgehaald of ingesteld.

Y

Hiermee wordt de waarde van de y-as van de bovenzijde van de rechthoek opgehaald of ingesteld.

Methoden

Name Description
Contains(Double, Double)

Geeft aan of de rechthoek de opgegeven x-coördinaat en y-coördinaat bevat.

Contains(Point)

Geeft aan of de rechthoek het opgegeven punt bevat.

Contains(Rect)

Geeft aan of de rechthoek de opgegeven rechthoek bevat.

Equals(Object)

Geeft aan of het opgegeven object gelijk is aan de huidige rechthoek.

Equals(Rect, Rect)

Geeft aan of de opgegeven rechthoeken gelijk zijn.

Equals(Rect)

Geeft aan of de opgegeven rechthoek gelijk is aan de huidige rechthoek.

GetHashCode()

Hiermee maakt u een hash-code voor de rechthoek.

Inflate(Double, Double)

Hiermee wordt de rechthoek uitgebreid of verkleind met behulp van de opgegeven breedte- en hoogtebedragen, in alle richtingen.

Inflate(Rect, Double, Double)

Hiermee maakt u een rechthoek die het gevolg is van het uitbreiden of verkleinen van de opgegeven rechthoek door de opgegeven breedte- en hoogtebedragen, in alle richtingen.

Inflate(Rect, Size)

Retourneert de rechthoek die het resultaat is van het uitbreiden van de opgegeven rechthoek door de opgegeven Size, in alle richtingen.

Inflate(Size)

Breidt de rechthoek uit met behulp van de opgegeven Size, in alle richtingen.

Intersect(Rect, Rect)

Retourneert het snijpunt van de opgegeven rechthoeken.

Intersect(Rect)

Zoekt het snijpunt van de huidige rechthoek en de opgegeven rechthoek en slaat het resultaat op als de huidige rechthoek.

IntersectsWith(Rect)

Geeft aan of de opgegeven rechthoek interseert met de huidige rechthoek.

Offset(Double, Double)

Hiermee verplaatst u de rechthoek door de opgegeven horizontale en verticale bedragen.

Offset(Rect, Double, Double)

Retourneert een rechthoek die wordt verschoven van de opgegeven rechthoek met behulp van de opgegeven horizontale en verticale bedragen.

Offset(Rect, Vector)

Retourneert een rechthoek die wordt verschoven van de opgegeven rechthoek met behulp van de opgegeven vector.

Offset(Vector)

Hiermee verplaatst u de rechthoek door de opgegeven vector.

Parse(String)

Hiermee maakt u een nieuwe rechthoek op basis van de opgegeven tekenreeksweergave.

Scale(Double, Double)

Vermenigvuldigt de grootte van de huidige rechthoek met de opgegeven x- en y-waarden.

ToString()

Hiermee wordt een tekenreeksweergave van de rechthoek geretourneerd.

ToString(IFormatProvider)

Retourneert een tekenreeksweergave van de rechthoek met behulp van de opgegeven indelingsprovider.

Transform(Matrix)

Transformeert de rechthoek door de opgegeven matrix toe te passen.

Transform(Rect, Matrix)

Retourneert de rechthoek die het resultaat is van het toepassen van de opgegeven matrix op de opgegeven rechthoek.

Union(Point)

Breidt de huidige rechthoek precies genoeg uit om het opgegeven punt te bevatten.

Union(Rect, Point)

Hiermee maakt u een rechthoek die precies groot genoeg is om de opgegeven rechthoek en het opgegeven punt op te nemen.

Union(Rect, Rect)

Hiermee maakt u een rechthoek die precies groot genoeg is om de twee opgegeven rechthoeken te bevatten.

Union(Rect)

Breidt de huidige rechthoek precies genoeg uit om de opgegeven rechthoek te bevatten.

Operators

Name Description
Equality(Rect, Rect)

Vergelijkt twee rechthoeken voor exacte gelijkheid.

Inequality(Rect, Rect)

Vergelijkt twee rechthoeken voor ongelijkheid.

Expliciete interface-implementaties

Name Description
IFormattable.ToString(String, IFormatProvider)

Hiermee wordt de waarde van het huidige exemplaar opgemaakt met behulp van de opgegeven indeling.

Van toepassing op