RectangleF 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用指定的位置和大小,初始化 RectangleF 類別的新執行個體。
多載
RectangleF(Vector4) |
從指定的 Vector4,初始化 結構的新實例RectangleF。 |
RectangleF(PointF, SizeF) |
使用指定的位置和大小,初始化 RectangleF 類別的新執行個體。 |
RectangleF(Single, Single, Single, Single) |
使用指定的位置和大小,初始化 RectangleF 類別的新執行個體。 |
RectangleF(Vector4)
從指定的 Vector4,初始化 結構的新實例RectangleF。
public:
RectangleF(System::Numerics::Vector4 vector);
public RectangleF (System.Numerics.Vector4 vector);
new System.Drawing.RectangleF : System.Numerics.Vector4 -> System.Drawing.RectangleF
Public Sub New (vector As Vector4)
參數
- vector
- Vector4
來源向量。
適用於
RectangleF(PointF, SizeF)
使用指定的位置和大小,初始化 RectangleF 類別的新執行個體。
public:
RectangleF(System::Drawing::PointF location, System::Drawing::SizeF size);
public RectangleF (System.Drawing.PointF location, System.Drawing.SizeF size);
new System.Drawing.RectangleF : System.Drawing.PointF * System.Drawing.SizeF -> System.Drawing.RectangleF
Public Sub New (location As PointF, size As SizeF)
參數
範例
下列程式代碼範例示範如何使用 Implicit、 RectangleF和 Equality 成員。 此範例是設計來搭配 Windows Form 使用。 將此程式代碼貼到表單中,並在處理表單的事件Paint時呼叫 ConvertRectangleToRectangleF
方法,並傳遞e
為 PaintEventArgs。
private:
void ConvertRectangleToRectangleF( PaintEventArgs^ e )
{
// Create a rectangle.
Rectangle rectangle1 = Rectangle(30,40,50,100);
// Convert it to a RectangleF.
RectangleF convertedRectangle = rectangle1;
// Create a new RectangleF.
RectangleF rectangle2 = RectangleF(PointF(30.0F,40.0F),SizeF(50.0F,100.0F));
// Create a custom, partially transparent brush.
SolidBrush^ redBrush = gcnew SolidBrush( Color::FromArgb( 40, Color::Red ) );
// Compare the converted rectangle with the new one. If they
// are equal draw and fill the rectangles on the form.
if ( convertedRectangle == rectangle2 )
{
e->Graphics->FillRectangle( redBrush, rectangle2 );
}
// Dispose of the custom brush.
delete redBrush;
}
};
private void ConvertRectangleToRectangleF(PaintEventArgs e)
{
// Create a rectangle.
Rectangle rectangle1 = new Rectangle(30, 40, 50, 100);
// Convert it to a RectangleF.
RectangleF convertedRectangle = rectangle1;
// Create a new RectangleF.
RectangleF rectangle2 = new RectangleF(new PointF(30.0F, 40.0F),
new SizeF(50.0F, 100.0F));
// Create a custom, partially transparent brush.
SolidBrush redBrush = new SolidBrush(Color.FromArgb(40, Color.Red));
// Compare the converted rectangle with the new one. If they
// are equal draw and fill the rectangles on the form.
if (convertedRectangle == rectangle2)
{
e.Graphics.FillRectangle(redBrush, rectangle2);
}
// Dispose of the custom brush.
redBrush.Dispose();
}
Private Sub ConvertRectangleToRectangleF( _
ByVal e As PaintEventArgs)
' Create a rectangle.
Dim rectangle1 As New Rectangle(30, 40, 50, 100)
' Convert it to a RectangleF.
Dim convertedRectangle As RectangleF = _
RectangleF.op_Implicit(rectangle1)
' Create a new RectangleF.
Dim rectangle2 As New RectangleF(New PointF(30.0F, 40.0F), _
New SizeF(50.0F, 100.0F))
' Create a custom, partially transparent brush.
Dim redBrush As New SolidBrush(Color.FromArgb(40, Color.Red))
' Compare the converted rectangle with the new one. If they
' are equal, draw and fill the rectangles on the form.
If (RectangleF.op_Equality(convertedRectangle, rectangle2)) Then
e.Graphics.FillRectangle(redBrush, rectangle2)
End If
' Dispose of the custom brush.
redBrush.Dispose()
End Sub
適用於
RectangleF(Single, Single, Single, Single)
使用指定的位置和大小,初始化 RectangleF 類別的新執行個體。
public:
RectangleF(float x, float y, float width, float height);
public RectangleF (float x, float y, float width, float height);
new System.Drawing.RectangleF : single * single * single * single -> System.Drawing.RectangleF
Public Sub New (x As Single, y As Single, width As Single, height As Single)
參數
- x
- Single
矩形左上角的 X 座標。
- y
- Single
矩形左上角的 Y 座標。
- width
- Single
矩形的寬度。
- height
- Single
矩形的高度。
範例
下列程式代碼範例示範如何使用 RectangleF、 Round 和 Truncate 成員。 此範例是設計來搭配 Windows Form 使用。 將此程式代碼貼到表單中,並在處理表單的事件Paint時呼叫 RoundingAndTruncatingRectangles
方法,並傳遞e
為 PaintEventArgs。
private:
void RoundingAndTruncatingRectangles( PaintEventArgs^ e )
{
// Construct a new RectangleF.
RectangleF myRectangleF = RectangleF(30.6F,30.7F,40.8F,100.9F);
// Call the Round method.
Rectangle roundedRectangle = Rectangle::Round( myRectangleF );
// Draw the rounded rectangle in red.
Pen^ redPen = gcnew Pen( Color::Red,4.0f );
e->Graphics->DrawRectangle( redPen, roundedRectangle );
// Call the Truncate method.
Rectangle truncatedRectangle = Rectangle::Truncate( myRectangleF );
// Draw the truncated rectangle in white.
Pen^ whitePen = gcnew Pen( Color::White,4.0f );
e->Graphics->DrawRectangle( whitePen, truncatedRectangle );
// Dispose of the custom pens.
delete redPen;
delete whitePen;
}
private void RoundingAndTruncatingRectangles(PaintEventArgs e)
{
// Construct a new RectangleF.
RectangleF myRectangleF =
new RectangleF(30.6F, 30.7F, 40.8F, 100.9F);
// Call the Round method.
Rectangle roundedRectangle = Rectangle.Round(myRectangleF);
// Draw the rounded rectangle in red.
Pen redPen = new Pen(Color.Red, 4);
e.Graphics.DrawRectangle(redPen, roundedRectangle);
// Call the Truncate method.
Rectangle truncatedRectangle = Rectangle.Truncate(myRectangleF);
// Draw the truncated rectangle in white.
Pen whitePen = new Pen(Color.White, 4);
e.Graphics.DrawRectangle(whitePen, truncatedRectangle);
// Dispose of the custom pens.
redPen.Dispose();
whitePen.Dispose();
}
Private Sub RoundingAndTruncatingRectangles( _
ByVal e As PaintEventArgs)
' Construct a new RectangleF.
Dim myRectangleF As New RectangleF(30.6F, 30.7F, 40.8F, 100.9F)
' Call the Round method.
Dim roundedRectangle As Rectangle = Rectangle.Round(myRectangleF)
' Draw the rounded rectangle in red.
Dim redPen As New Pen(Color.Red, 4)
e.Graphics.DrawRectangle(redPen, roundedRectangle)
' Call the Truncate method.
Dim truncatedRectangle As Rectangle = _
Rectangle.Truncate(myRectangleF)
' Draw the truncated rectangle in white.
Dim whitePen As New Pen(Color.White, 4)
e.Graphics.DrawRectangle(whitePen, truncatedRectangle)
' Dispose of the custom pens.
redPen.Dispose()
whitePen.Dispose()
End Sub