Rectangle.IsEmpty 属性

定义

测试此 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

属性值

如果此 RectangleWidthHeightXY 属性都具有零值,此属性将返回 true;否则将返回 false

属性

示例

下面的代码示例演示 、 IntersectIsEmptyIntersectsWith 成员。 此示例应与 Windows 窗体一起使用。 将此代码粘贴到窗体中,并在处理窗体的 Paint 事件时调用此方法,作为 ePaintEventArgs传递。

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

适用于