Rectangle.IsEmpty 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
測試這個 Rectangle 的所有數值屬性是否具有零值。
public:
property bool IsEmpty { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool IsEmpty { get; }
public bool IsEmpty { get; }
[<System.ComponentModel.Browsable(false)>]
member this.IsEmpty : bool
member this.IsEmpty : bool
Public ReadOnly Property IsEmpty As Boolean
屬性值
如果這個 Rectangle 的 Width、Height、X 和 Y 屬性都具有零值,則這個屬性會傳回 true
,否則傳回 false
。
- 屬性
範例
下列程式代碼範例示範 Intersect、 IsEmpty 和 IntersectsWith 成員。 此範例應該與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件 Paint 時呼叫此方法,並 e
傳遞為 PaintEventArgs。
private:
void InstanceRectangleIntersection( PaintEventArgs^ e )
{
Rectangle rectangle1 = Rectangle(50,50,200,100);
Rectangle rectangle2 = Rectangle(70,20,100,200);
e->Graphics->DrawRectangle( Pens::Black, rectangle1 );
e->Graphics->DrawRectangle( Pens::Red, rectangle2 );
if ( rectangle1.IntersectsWith( rectangle2 ) )
{
rectangle1.Intersect( rectangle2 );
if ( !rectangle1.IsEmpty )
{
e->Graphics->FillRectangle( Brushes::Green, rectangle1 );
}
}
}
private void InstanceRectangleIntersection(PaintEventArgs e)
{
Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);
Rectangle rectangle2 = new Rectangle(70, 20, 100, 200);
e.Graphics.DrawRectangle(Pens.Black, rectangle1);
e.Graphics.DrawRectangle(Pens.Red, rectangle2);
if (rectangle1.IntersectsWith(rectangle2))
{
rectangle1.Intersect(rectangle2);
if (!rectangle1.IsEmpty)
{
e.Graphics.FillRectangle(Brushes.Green, rectangle1);
}
}
}
Private Sub InstanceRectangleIntersection( _
ByVal e As PaintEventArgs)
Dim rectangle1 As New Rectangle(50, 50, 200, 100)
Dim rectangle2 As New Rectangle(70, 20, 100, 200)
e.Graphics.DrawRectangle(Pens.Black, rectangle1)
e.Graphics.DrawRectangle(Pens.Red, rectangle2)
If (rectangle1.IntersectsWith(rectangle2)) Then
rectangle1.Intersect(rectangle2)
If Not (rectangle1.IsEmpty) Then
e.Graphics.FillRectangle(Brushes.Green, rectangle1)
End If
End If
End Sub