Rect Rect Rect Rect Struct

定義

四角形の幅、高さ、場所を記述します。Describes the width, height, and location of a rectangle.

public value class Rect : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.RectConverter))]
[System.Serializable]
public struct Rect : IFormattable
type Rect = struct
    interface IFormattable
Public Structure Rect
Implements IFormattable
継承
属性
実装

次の例は、構造体をRect使用して、XAML を使用して四角形のサイズと位置を指定する方法を示しています。The following example shows how to use a Rect structure to specify the dimensions and location of a rectangle using XAML.

using System;
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 my Rect1 = 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
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>

次の例は、コードを使用して四角形を作成し、ページに追加する方法を示しています。The following example shows how to use code to create a rectangle and add it to the page. また、この例では、新しい四角形のサイズと座標に関する情報を検索し、そのTextBox情報を四角形の下のに表示する方法も示しています。The example also illustrates how to find size and coordinate information about the new rectangle and render the information in a TextBox below the rectangle.

// 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;
}

注釈

XAML 属性の使用方法XAML Attribute Usage

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

XAML 値XAML Values

xx
System.Double

四角形の左辺の x 座標位置。The x-coordinate location of the left side of the rectangle.

yy
System.Double

四角形の上辺の y 座標位置。The y-coordinate location of the top side of the rectangle.

widthwidth
System.Double

四角形Widthのを表す負でない値。A non-negative value that represents the Width of the rectangle.

heightheight
System.Double

四角形Heightのを表す負でない値。A non-negative value that represents the Height of the rectangle.

コンストラクター

Rect(Size) Rect(Size) Rect(Size) Rect(Size)

指定したサイズを持ち、座標 (0,0) に位置する Rect 構造体の新しいインスタンスを初期化します。Initializes a new instance of the Rect structure that is of the specified size and is located at (0,0).

Rect(Point, Point) Rect(Point, Point) Rect(Point, Point) Rect(Point, Point)

指定した 2 つの点をちょうど格納できる大きさを持つ、Rect 構造体の新しいインスタンスを初期化します。Initializes a new instance of the Rect structure that is exactly large enough to contain the two specified points.

Rect(Point, Size) Rect(Point, Size) Rect(Point, Size) Rect(Point, Size)

指定した左上隅の位置および指定した幅と高さを持つ、Rect 構造体の新しいインスタンスを初期化します。Initializes a new instance of the Rect structure that has the specified top-left corner location and the specified width and height.

Rect(Point, Vector) Rect(Point, Vector) Rect(Point, Vector) Rect(Point, Vector)

指定した点および指定した点とベクターの和をちょうど格納できる大きさを持つ、Rect 構造体の新しいインスタンスを初期化します。Initializes a new instance of the Rect structure that is exactly large enough to contain the specified point and the sum of the specified point and the specified vector.

Rect(Double, Double, Double, Double) Rect(Double, Double, Double, Double) Rect(Double, Double, Double, Double) Rect(Double, Double, Double, Double)

指定した x 座標、y 座標、幅、および高さを持つ、Rect 構造体の新しいインスタンスを初期化します。Initializes a new instance of the Rect structure that has the specified x-coordinate, y-coordinate, width, and height.

プロパティ

Bottom Bottom Bottom Bottom

四角形の底辺の y 軸の値を取得します。Gets the y-axis value of the bottom of the rectangle.

BottomLeft BottomLeft BottomLeft BottomLeft

四角形の左下隅の位置を取得します。Gets the position of the bottom-left corner of the rectangle

BottomRight BottomRight BottomRight BottomRight

四角形の右下隅の位置を取得します。Gets the position of the bottom-right corner of the rectangle.

Empty Empty Empty Empty

位置や領域を持たない四角形を表す特殊な値を取得します。Gets a special value that represents a rectangle with no position or area.

Height Height Height Height

四角形の高さを取得または設定します。Gets or sets the height of the rectangle.

IsEmpty IsEmpty IsEmpty IsEmpty

四角形が Empty の四角形かどうかを示す値を取得します。Gets a value that indicates whether the rectangle is the Empty rectangle.

Left Left Left Left

四角形の左辺の x 軸の値を取得します。Gets the x-axis value of the left side of the rectangle.

Location Location Location Location

四角形の左上隅の位置を取得または設定します。Gets or sets the position of the top-left corner of the rectangle.

Right Right Right Right

四角形の右辺の x 軸の値を取得します。Gets the x-axis value of the right side of the rectangle.

Size Size Size Size

四角形の幅および高さを取得または設定します。Gets or sets the width and height of the rectangle.

Top Top Top Top

四角形の上辺の y 軸の位置を取得します。Gets the y-axis position of the top of the rectangle.

TopLeft TopLeft TopLeft TopLeft

四角形の左上隅の位置を取得します。Gets the position of the top-left corner of the rectangle.

TopRight TopRight TopRight TopRight

四角形の右上隅の位置を取得します。Gets the position of the top-right corner of the rectangle.

Width Width Width Width

四角形の幅を取得または設定します。Gets or sets the width of the rectangle.

X X X X

四角形の左辺の x 軸の値を取得または設定します。Gets or sets the x-axis value of the left side of the rectangle.

Y Y Y Y

四角形の上辺の y 軸の値を取得または設定します。Gets or sets the y-axis value of the top side of the rectangle.

メソッド

Contains(Point) Contains(Point) Contains(Point) Contains(Point)

四角形に指定した点が含まれているかどうかを示します。Indicates whether the rectangle contains the specified point.

Contains(Rect) Contains(Rect) Contains(Rect) Contains(Rect)

指定した四角形が、四角形に含まれているかどうかを示します。Indicates whether the rectangle contains the specified rectangle.

Contains(Double, Double) Contains(Double, Double) Contains(Double, Double) Contains(Double, Double)

指定した x 座標と y 座標が、四角形に含まれているかどうかを示します。Indicates whether the rectangle contains the specified x-coordinate and y-coordinate.

Equals(Rect, Rect) Equals(Rect, Rect) Equals(Rect, Rect) Equals(Rect, Rect)

指定した四角形が等しいかどうかを示します。Indicates whether the specified rectangles are equal.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが現在の四角形と等しいかどうかを示します。Indicates whether the specified object is equal to the current rectangle.

Equals(Rect) Equals(Rect) Equals(Rect) Equals(Rect)

指定した四角形が現在の四角形と等しいかどうかを示します。Indicates whether the specified rectangle is equal to the current rectangle.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

四角形のハッシュ コードを作成します。Creates a hash code for the rectangle.

Inflate(Size) Inflate(Size) Inflate(Size) Inflate(Size)

すべての方向に、指定した Size を使用して四角形を拡大します。Expands the rectangle by using the specified Size, in all directions.

Inflate(Double, Double) Inflate(Double, Double) Inflate(Double, Double) Inflate(Double, Double)

すべての方向に、指定した幅および高さの量を使用して四角形を拡大または縮小します。Expands or shrinks the rectangle by using the specified width and height amounts, in all directions.

Inflate(Rect, Size) Inflate(Rect, Size) Inflate(Rect, Size) Inflate(Rect, Size)

指定した四角形を、すべての方向に指定した Size だけ拡大した四角形を返します。Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.

Inflate(Rect, Double, Double) Inflate(Rect, Double, Double) Inflate(Rect, Double, Double) Inflate(Rect, Double, Double)

指定した四角形を、すべての方向に指定した幅および高さの量だけ拡大または縮小した四角形を作成します。Creates a rectangle that results from expanding or shrinking the specified rectangle by the specified width and height amounts, in all directions.

Intersect(Rect) Intersect(Rect) Intersect(Rect) Intersect(Rect)

現在の四角形と指定した四角形の交差部分を求め、結果を現在の四角形として保存します。Finds the intersection of the current rectangle and the specified rectangle, and stores the result as the current rectangle.

Intersect(Rect, Rect) Intersect(Rect, Rect) Intersect(Rect, Rect) Intersect(Rect, Rect)

指定した四角形の交差部分を返します。Returns the intersection of the specified rectangles.

IntersectsWith(Rect) IntersectsWith(Rect) IntersectsWith(Rect) IntersectsWith(Rect)

指定した四角形が、現在の四角形と交差するかどうかを示します。Indicates whether the specified rectangle intersects with the current rectangle.

Offset(Vector) Offset(Vector) Offset(Vector) Offset(Vector)

指定したベクターだけ四角形を移動します。Moves the rectangle by the specified vector.

Offset(Double, Double) Offset(Double, Double) Offset(Double, Double) Offset(Double, Double)

四角形を水平方向および垂直方向に指定した量だけ移動します。Moves the rectangle by the specified horizontal and vertical amounts.

Offset(Rect, Vector) Offset(Rect, Vector) Offset(Rect, Vector) Offset(Rect, Vector)

指定したベクターを使用して、指定した四角形からのオフセットである四角形を返します。Returns a rectangle that is offset from the specified rectangle by using the specified vector.

Offset(Rect, Double, Double) Offset(Rect, Double, Double) Offset(Rect, Double, Double) Offset(Rect, Double, Double)

指定した水平方向および垂直後方の量を使用して、指定した四角形からのオフセットである四角形を返します。Returns a rectangle that is offset from the specified rectangle by using the specified horizontal and vertical amounts.

Parse(String) Parse(String) Parse(String) Parse(String)

指定した文字列形式から新しい四角形を作成します。Creates a new rectangle from the specified string representation.

Scale(Double, Double) Scale(Double, Double) Scale(Double, Double) Scale(Double, Double)

現在の四角形のサイズと指定した x および y の値を乗算します。Multiplies the size of the current rectangle by the specified x and y values.

ToString() ToString() ToString() ToString()

四角形の文字列形式を返します。Returns a string representation of the rectangle.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

指定した書式プロバイダーを使用して、四角形の文字列形式を返します。Returns a string representation of the rectangle by using the specified format provider.

Transform(Matrix) Transform(Matrix) Transform(Matrix) Transform(Matrix)

指定した行列を適用して四角形を変換します。Transforms the rectangle by applying the specified matrix.

Transform(Rect, Matrix) Transform(Rect, Matrix) Transform(Rect, Matrix) Transform(Rect, Matrix)

指定した四角形に指定した行列を適用した四角形を返します。Returns the rectangle that results from applying the specified matrix to the specified rectangle.

Union(Point) Union(Point) Union(Point) Union(Point)

指定した点をちょうど格納できる大きさになるように、現在の四角形を拡大します。Expands the current rectangle exactly enough to contain the specified point.

Union(Rect) Union(Rect) Union(Rect) Union(Rect)

指定した四角形をちょうど格納できる大きさになるように、現在の四角形を拡大します。Expands the current rectangle exactly enough to contain the specified rectangle.

Union(Rect, Point) Union(Rect, Point) Union(Rect, Point) Union(Rect, Point)

指定した四角形と指定した点をちょうど格納できる大きさの四角形を作成します。Creates a rectangle that is exactly large enough to include the specified rectangle and the specified point.

Union(Rect, Rect) Union(Rect, Rect) Union(Rect, Rect) Union(Rect, Rect)

指定した 2 つの四角形をちょうど格納できる大きさの四角形を作成します。Creates a rectangle that is exactly large enough to contain the two specified rectangles.

演算子

Equality(Rect, Rect) Equality(Rect, Rect) Equality(Rect, Rect) Equality(Rect, Rect)

2 つの四角形を比較し、完全に等しいかどうかを判断します。Compares two rectangles for exact equality.

Inequality(Rect, Rect) Inequality(Rect, Rect) Inequality(Rect, Rect) Inequality(Rect, Rect)

2 つの四角形を比較し、等しくないかどうかを判断します。Compares two rectangles for inequality.

明示的なインターフェイスの実装

IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider)

指定した書式を使用して、現在のインスタンスの値に書式を付けます。Formats the value of the current instance using the specified format.

適用対象