Rect Estrutura
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Descreve a largura, altura e localização de um retângulo.
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
- Herança
- Atributos
- Implementações
Exemplos
O exemplo seguinte mostra como usar uma Rect estrutura para especificar as dimensões e a localização de um retângulo usando 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>
O exemplo seguinte mostra como usar código para criar um retângulo e adicioná-lo à página. O exemplo também ilustra como encontrar informação de tamanho e coordenada sobre o novo retângulo e renderizar a informação abaixo TextBox do retângulo.
// 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;
}
Observações
Uso de atributos XAML
<object property="x,y,width,height"/>
Valores XAML
A localização coordenada x do lado esquerdo do retângulo.
A localização da coordenada y do lado superior do retângulo.
larguraSystem.Double
Um valor não negativo que representa o Width do retângulo.
AlturaSystem.Double
Um valor não negativo que representa o Height do retângulo.
Construtores
| Name | Description |
|---|---|
| Rect(Double, Double, Double, Double) |
Inicializa uma nova instância da Rect estrutura que tem as coordenadas x, coordenadas y, largura e altura especificadas. |
| Rect(Point, Point) |
Inicializa uma nova instância da Rect estrutura que é exatamente suficientemente grande para conter os dois pontos especificados. |
| Rect(Point, Size) |
Inicializa uma nova instância da Rect estrutura que tenha a localização do canto superior esquerdo especificada e a largura e altura especificadas. |
| Rect(Point, Vector) |
Inicializa uma nova instância da Rect estrutura que seja exatamente suficientemente grande para conter o ponto especificado e a soma do ponto especificado e do vetor especificado. |
| Rect(Size) |
Inicializa uma nova instância da Rect estrutura com o tamanho especificado e localizada em (0,0). |
Propriedades
| Name | Description |
|---|---|
| Bottom |
Obtém o valor do eixo y da parte inferior do retângulo. |
| BottomLeft |
Obtém a posição do canto inferior esquerdo do retângulo. |
| BottomRight |
Obtém a posição do canto inferior direito do retângulo. |
| Empty |
Recebe um valor especial que representa um retângulo sem posição ou área. |
| Height |
Obtém ou define a altura do retângulo. |
| IsEmpty |
Obtém um valor que indica se o retângulo é o Empty rectângulo. |
| Left |
Obtém o valor do eixo x do lado esquerdo do retângulo. |
| Location |
Obtém ou define a posição do canto superior esquerdo do retângulo. |
| Right |
Obtém o valor do eixo x do lado direito do retângulo. |
| Size |
Obtém ou define a largura e a altura do retângulo. |
| Top |
Obtém a posição do eixo y do topo do retângulo. |
| TopLeft |
Obtém a posição do canto superior esquerdo do retângulo. |
| TopRight |
Obtém a posição do canto superior direito do retângulo. |
| Width |
Obtém ou define a largura do retângulo. |
| X |
Obtém ou define o valor do eixo x do lado esquerdo do retângulo. |
| Y |
Obtém ou define o valor do eixo y do lado superior do retângulo. |
Métodos
| Name | Description |
|---|---|
| Contains(Double, Double) |
Indica se o retângulo contém as coordenadas x e y especificadas. |
| Contains(Point) |
Indica se o retângulo contém o ponto especificado. |
| Contains(Rect) |
Indica se o retângulo contém o retângulo especificado. |
| Equals(Object) |
Indica se o objeto especificado é igual ao retângulo atual. |
| Equals(Rect, Rect) |
Indica se os retângulos especificados são iguais. |
| Equals(Rect) |
Indica se o retângulo especificado é igual ao retângulo atual. |
| GetHashCode() |
Cria um código de hash para o retângulo. |
| Inflate(Double, Double) |
Expande ou encolhe o retângulo usando as quantidades especificadas de largura e altura, em todas as direções. |
| Inflate(Rect, Double, Double) |
Cria um retângulo que resulta da expansão ou encolhimento do retângulo especificado pelas quantidades de largura e altura especificadas, em todas as direções. |
| Inflate(Rect, Size) |
Devolve o retângulo que resulta da expansão do retângulo especificado pelo especificado Size, em todas as direções. |
| Inflate(Size) |
Expande o retângulo usando o especificado Size, em todas as direções. |
| Intersect(Rect, Rect) |
Devolve a interseção dos retângulos especificados. |
| Intersect(Rect) |
Encontra a interseção do retângulo atual com o retângulo especificado, e armazena o resultado como o retângulo atual. |
| IntersectsWith(Rect) |
Indica se o retângulo especificado intersecta com o retângulo atual. |
| Offset(Double, Double) |
Move o retângulo pelas quantidades horizontais e verticais especificadas. |
| Offset(Rect, Double, Double) |
Devolve um retângulo que está deslocado em relação ao rectângulo especificado usando as quantidades horizontais e verticais especificadas. |
| Offset(Rect, Vector) |
Devolve um retângulo que está deslocado em relação ao retângulo especificado usando o vetor especificado. |
| Offset(Vector) |
Move o retângulo pelo vetor especificado. |
| Parse(String) |
Cria um novo retângulo a partir da representação da cadeia especificada. |
| Scale(Double, Double) |
Multiplica o tamanho do retângulo atual pelos valores x e y especificados. |
| ToString() |
Devolve uma representação em cadeia do retângulo. |
| ToString(IFormatProvider) |
Devolve uma representação em cadeia do retângulo usando o fornecedor de formato especificado. |
| Transform(Matrix) |
Transforma o retângulo aplicando a matriz especificada. |
| Transform(Rect, Matrix) |
Devolve o retângulo que resulta da aplicação da matriz especificada ao retângulo especificado. |
| Union(Point) |
Expande o retângulo atual exatamente o suficiente para conter o ponto especificado. |
| Union(Rect, Point) |
Cria um retângulo exatamente suficientemente grande para incluir o retângulo especificado e o ponto indicado. |
| Union(Rect, Rect) |
Cria um retângulo exatamente suficientemente grande para conter os dois retângulos especificados. |
| Union(Rect) |
Expande o retângulo atual exatamente o suficiente para conter o retângulo especificado. |
Operadores
| Name | Description |
|---|---|
| Equality(Rect, Rect) |
Compara dois retângulos para igualdade exata. |
| Inequality(Rect, Rect) |
Compara dois retângulos para a desigualdade. |
Implementações de Interface Explícita
| Name | Description |
|---|---|
| IFormattable.ToString(String, IFormatProvider) |
Formata o valor da instância atual usando o formato especificado. |