Graphics.IsVisible 方法

定义

指示由一对坐标指定的点是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the point specified by a pair of coordinates is contained within the visible clip region of this Graphics.

重载

IsVisible(Point)

指示指定的 Point 结构是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the specified Point structure is contained within the visible clip region of this Graphics.

IsVisible(PointF)

指示指定的 PointF 结构是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the specified PointF structure is contained within the visible clip region of this Graphics.

IsVisible(Rectangle)

指示 Rectangle 结构指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a Rectangle structure is contained within the visible clip region of this Graphics.

IsVisible(RectangleF)

指示 RectangleF 结构指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a RectangleF structure is contained within the visible clip region of this Graphics.

IsVisible(Int32, Int32)

指示由一对坐标指定的点是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the point specified by a pair of coordinates is contained within the visible clip region of this Graphics.

IsVisible(Single, Single)

指示由一对坐标指定的点是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the point specified by a pair of coordinates is contained within the visible clip region of this Graphics.

IsVisible(Int32, Int32, Int32, Int32)

指示由一对坐标、一个宽度和一个高度指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a pair of coordinates, a width, and a height is contained within the visible clip region of this Graphics.

IsVisible(Single, Single, Single, Single)

指示由一对坐标、一个宽度和一个高度指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a pair of coordinates, a width, and a height is contained within the visible clip region of this Graphics.

IsVisible(Point)

指示指定的 Point 结构是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the specified Point structure is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(System::Drawing::Point point);
public bool IsVisible (System.Drawing.Point point);
member this.IsVisible : System.Drawing.Point -> bool
Public Function IsVisible (point As Point) As Boolean

参数

point
Point

要测试其可见性的 Point 结构。Point structure to test for visibility.

返回

Boolean

如果 point 参数指定的点包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the point specified by the point parameter is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个点,一个位于剪辑区域内,一个在外部。Creates two points, one inside the clipping region and one outside.

  • 测试每个点的可见性并仅绘制可见的点。Tests each of the points for visibility and draws only the visible one.

结果是位于剪辑区域内的一个小红色圆圈。The result is one small red circle, which is within the clip region.

public:
   void IsVisiblePoint( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of points.
      int x1 = 100;
      int y1 = 100;
      int x2 = 200;
      int y2 = 200;
      Point point1 = Point(x1,y1);
      Point point2 = Point(x2,y2);

      // If point is visible, fill ellipse that represents it.
      if ( e->Graphics->IsVisible( point1 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Red ), x1, y1, 10, 10 );
      }

      if ( e->Graphics->IsVisible( point2 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Blue ), x2, y2, 10, 10 );
      }
   }
private void IsVisiblePoint(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of points.
    int x1 = 100;
    int y1 = 100;
    int x2 = 200;
    int y2 = 200;
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x2, y2);

    // If point is visible, fill ellipse that represents it.
    if (e.Graphics.IsVisible(point1))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Red), x1, y1, 10, 10);
    }
    if (e.Graphics.IsVisible(point2))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x2, y2, 10, 10);
    }
}
Private Sub IsVisiblePoint(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of points.
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim x2 As Integer = 200
    Dim y2 As Integer = 200
    Dim point1 As New Point(x1, y1)
    Dim point2 As New Point(x2, y2)

    ' If point is visible, fill ellipse that represents it.
    If e.Graphics.IsVisible(point1) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Red), x1, y1, _
        10, 10)
    End If
    If e.Graphics.IsVisible(point2) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Blue), x2, y2, _
        10, 10)
    End If
End Sub

适用于

IsVisible(PointF)

指示指定的 PointF 结构是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the specified PointF structure is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(System::Drawing::PointF point);
public bool IsVisible (System.Drawing.PointF point);
member this.IsVisible : System.Drawing.PointF -> bool
Public Function IsVisible (point As PointF) As Boolean

参数

point
PointF

要测试其可见性的 PointF 结构。PointF structure to test for visibility.

返回

Boolean

如果 point 参数指定的点包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the point specified by the point parameter is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为窗体图形的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics of the form using Replace.

  • 创建两个点,一个位于剪辑区域内,一个在外部。Creates two points, one inside the clipping region and one outside.

  • 测试每个点的可见性并仅绘制可见的点。Tests each of the points for visibility and draws only the visible one.

结果是位于剪辑区域内的一个小红色圆圈。The result is one small red circle, which is within the clip region.

public:
   void IsVisiblePointF( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of points.
      float x1 = 100.0F;
      float y1 = 100.0F;
      float x2 = 200.0F;
      float y2 = 200.0F;
      PointF point1 = PointF(x1,y1);
      PointF point2 = PointF(x2,y2);

      // If point is visible, fill ellipse that represents it.
      if ( e->Graphics->IsVisible( point1 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Red ), x1, y1, 10.0F, 10.0F );
      }

      if ( e->Graphics->IsVisible( point2 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Blue ), x2, y2, 10.0F, 10.0F );
      }
   }
private void IsVisiblePointF(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of points.
    float x1 = 100.0F;
    float y1 = 100.0F;
    float x2 = 200.0F;
    float y2 = 200.0F;
    PointF point1 = new PointF(x1, y1);
    PointF point2 = new PointF(x2, y2);

    // If point is visible, fill ellipse that represents it.
    if (e.Graphics.IsVisible(point1))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Red), x1, y1, 10.0F, 10.0F);
    }
    if (e.Graphics.IsVisible(point2))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x2, y2, 10.0F, 10.0F);
    }
}
Private Sub IsVisiblePointF(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of points.
    Dim x1 As Single = 100.0F
    Dim y1 As Single = 100.0F
    Dim x2 As Single = 200.0F
    Dim y2 As Single = 200.0F
    Dim point1 As New PointF(x1, y1)
    Dim point2 As New PointF(x2, y2)

    ' If point is visible, fill ellipse that represents it.
    If e.Graphics.IsVisible(point1) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Red), x1, y1, _
        10.0F, 10.0F)
    End If
    If e.Graphics.IsVisible(point2) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Blue), x2, y2, _
        10.0F, 10.0F)
    End If
End Sub

适用于

IsVisible(Rectangle)

指示 Rectangle 结构指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a Rectangle structure is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(System::Drawing::Rectangle rect);
public bool IsVisible (System.Drawing.Rectangle rect);
member this.IsVisible : System.Drawing.Rectangle -> bool
Public Function IsVisible (rect As Rectangle) As Boolean

参数

rect
Rectangle

要测试其可见性的 Rectangle 结构。Rectangle structure to test for visibility.

返回

Boolean

如果 rect 参数指定的矩形包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the rectangle specified by the rect parameter is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个矩形的位置和大小,一个矩形位于剪辑区域内,一个在外部。Creates the location and size of two rectangles, one inside the clipping region and one outside.

  • 测试每个矩形的可见性并仅绘制可见的矩形。Tests each of the rectangles for visibility and draws only the visible one.

结果为一个小的红色矩形,位于剪辑区域内。The result is one small red rectangle, which is within the clip region.

public:
   void IsVisibleRectangle( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of rectangles.
      Rectangle rect1 = Rectangle(100,100,20,20);
      Rectangle rect2 = Rectangle(200,200,20,20);

      // If rectangle is visible, fill it.
      if ( e->Graphics->IsVisible( rect1 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), rect1 );
      }

      if ( e->Graphics->IsVisible( rect2 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), rect2 );
      }
   }
private void IsVisibleRectangle(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of rectangles.
    Rectangle rect1 = new Rectangle(100, 100, 20, 20);
    Rectangle rect2 = new Rectangle(200, 200, 20, 20);

    // If rectangle is visible, fill it.
    if (e.Graphics.IsVisible(rect1))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Red), rect1);
    }
    if (e.Graphics.IsVisible(rect2))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Blue), rect2);
    }
}
Private Sub IsVisibleRectangle(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of rectangles.
    Dim rect1 As New Rectangle(100, 100, 20, 20)
    Dim rect2 As New Rectangle(200, 200, 20, 20)

    ' If rectangle is visible, fill it.
    If e.Graphics.IsVisible(rect1) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect1)
    End If
    If e.Graphics.IsVisible(rect2) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Blue), rect2)
    End If
End Sub

适用于

IsVisible(RectangleF)

指示 RectangleF 结构指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a RectangleF structure is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(System::Drawing::RectangleF rect);
public bool IsVisible (System.Drawing.RectangleF rect);
member this.IsVisible : System.Drawing.RectangleF -> bool
Public Function IsVisible (rect As RectangleF) As Boolean

参数

rect
RectangleF

要测试其可见性的 RectangleF 结构。RectangleF structure to test for visibility.

返回

Boolean

如果 rect 参数指定的矩形包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the rectangle specified by the rect parameter is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个矩形,一个位于剪辑区域内,一个在外部。Creates two rectangles, one inside the clipping region and one outside.

  • 测试每个矩形的可见性并仅绘制可见的矩形。Tests each of the rectangles for visibility and draws only the visible one.

结果为一个小的红色矩形,位于剪辑区域内。The result is one small red rectangle, which is within the clip region.

public:
   void IsVisibleRectangleF( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of rectangles.
      RectangleF rect1 = RectangleF(100.0F,100.0F,20.0F,20.0F);
      RectangleF rect2 = RectangleF(200.0F,200.0F,20.0F,20.0F);

      // If rectangle is visible, fill it.
      if ( e->Graphics->IsVisible( rect1 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), rect1 );
      }

      if ( e->Graphics->IsVisible( rect2 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), rect2 );
      }
   }
private void IsVisibleRectangleF(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of rectangles.
    RectangleF rect1 = new RectangleF(100.0F, 100.0F, 20.0F, 20.0F);
    RectangleF rect2 = new RectangleF(200.0F, 200.0F, 20.0F, 20.0F);

    // If rectangle is visible, fill it.
    if (e.Graphics.IsVisible(rect1))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Red), rect1);
    }
    if (e.Graphics.IsVisible(rect2))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Blue), rect2);
    }
}
Private Sub IsVisibleRectangleF(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of rectangles.
    Dim rect1 As New RectangleF(100.0F, 100.0F, 20.0F, 20.0F)
    Dim rect2 As New RectangleF(200.0F, 200.0F, 20.0F, 20.0F)

    ' If rectangle is visible, fill it.
    If e.Graphics.IsVisible(rect1) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect1)
    End If
    If e.Graphics.IsVisible(rect2) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Blue), rect2)
    End If
End Sub

适用于

IsVisible(Int32, Int32)

指示由一对坐标指定的点是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the point specified by a pair of coordinates is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(int x, int y);
public bool IsVisible (int x, int y);
member this.IsVisible : int * int -> bool
Public Function IsVisible (x As Integer, y As Integer) As Boolean

参数

x
Int32

要测试其可见性的点的 x 坐标。The x-coordinate of the point to test for visibility.

y
Int32

要测试其可见性的点的 y 坐标。The y-coordinate of the point to test for visibility.

返回

Boolean

如果由 xy 参数定义的点包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the point defined by the x and y parameters is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个点,一个位于剪辑区域内,一个在外部。Creates two points, one inside the clipping region and one outside.

  • 测试每个点的可见性并仅绘制可见的点。Tests each of the points for visibility and draws only the visible one.

结果是位于剪辑区域内的一个小红色圆圈。The result is one small red circle, which is within the clip region.

public:
   void IsVisibleInt( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of points.
      int x1 = 100;
      int y1 = 100;
      int x2 = 200;
      int y2 = 200;

      // If point is visible, fill ellipse that represents it.
      if ( e->Graphics->IsVisible( x1, y1 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Red ), x1, y1, 10, 10 );
      }

      if ( e->Graphics->IsVisible( x2, y2 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Blue ), x2, y2, 10, 10 );
      }
   }
private void IsVisibleInt(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of points.
    int x1 = 100;
    int y1 = 100;
    int x2 = 200;
    int y2 = 200;

    // If point is visible, fill ellipse that represents it.
    if (e.Graphics.IsVisible(x1, y1))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Red), x1, y1, 10, 10);
    }
    if (e.Graphics.IsVisible(x2, y2))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x2, y2, 10, 10);
    }
}
Private Sub IsVisibleInt(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of points.
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim x2 As Integer = 200
    Dim y2 As Integer = 200

    ' If point is visible, fill ellipse that represents it.
    If e.Graphics.IsVisible(x1, y1) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Red), x1, y1, _
        10, 10)
    End If
    If e.Graphics.IsVisible(x2, y2) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Blue), x2, y2, _
        10, 10)
    End If
End Sub

适用于

IsVisible(Single, Single)

指示由一对坐标指定的点是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the point specified by a pair of coordinates is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(float x, float y);
public bool IsVisible (float x, float y);
member this.IsVisible : single * single -> bool
Public Function IsVisible (x As Single, y As Single) As Boolean

参数

x
Single

要测试其可见性的点的 x 坐标。The x-coordinate of the point to test for visibility.

y
Single

要测试其可见性的点的 y 坐标。The y-coordinate of the point to test for visibility.

返回

Boolean

如果由 xy 参数定义的点包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the point defined by the x and y parameters is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个点,一个位于剪辑区域内,一个在外部。Creates two points, one inside the clipping region and one outside.

  • 测试每个点的可见性并仅绘制可见的点。Tests each of the points for visibility and draws only the visible one.

结果是位于剪辑区域内的一个小红色圆圈。The result is one small red circle, which is within the clip region.

public:
   void IsVisibleFloat( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of points.
      float x1 = 100.0F;
      float y1 = 100.0F;
      float x2 = 200.0F;
      float y2 = 200.0F;

      // If point is visible, fill ellipse that represents it.
      if ( e->Graphics->IsVisible( x1, y1 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Red ), x1, y1, 10.0F, 10.0F );
      }

      if ( e->Graphics->IsVisible( x2, y2 ) )
      {
         e->Graphics->FillEllipse( gcnew SolidBrush( Color::Blue ), x2, y2, 10.0F, 10.0F );
      }
   }
private void IsVisibleFloat(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of points.
    float x1 = 100.0F;
    float y1 = 100.0F;
    float x2 = 200.0F;
    float y2 = 200.0F;

    // If point is visible, fill ellipse that represents it.
    if (e.Graphics.IsVisible(x1, y1))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Red), x1, y1, 10.0F, 10.0F);
    }
    if (e.Graphics.IsVisible(x2, y2))
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x2, y2, 10.0F, 10.0F);
    }
}
Private Sub IsVisibleFloat(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of points.
    Dim x1 As Single = 100.0F
    Dim y1 As Single = 100.0F
    Dim x2 As Single = 200.0F
    Dim y2 As Single = 200.0F

    ' If point is visible, fill ellipse that represents it.
    If e.Graphics.IsVisible(x1, y1) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Red), x1, y1, _
        10.0F, 10.0F)
    End If
    If e.Graphics.IsVisible(x2, y2) Then
        e.Graphics.FillEllipse(New SolidBrush(Color.Blue), x2, y2, _
        10.0F, 10.0F)
    End If
End Sub

适用于

IsVisible(Int32, Int32, Int32, Int32)

指示由一对坐标、一个宽度和一个高度指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a pair of coordinates, a width, and a height is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(int x, int y, int width, int height);
public bool IsVisible (int x, int y, int width, int height);
member this.IsVisible : int * int * int * int -> bool
Public Function IsVisible (x As Integer, y As Integer, width As Integer, height As Integer) As Boolean

参数

x
Int32

要测试其可见性的矩形的左上角的 x 坐标。The x-coordinate of the upper-left corner of the rectangle to test for visibility.

y
Int32

要测试其可见性的矩形的左上角的 y 坐标。The y-coordinate of the upper-left corner of the rectangle to test for visibility.

width
Int32

要测试其可见性的矩形的宽度。Width of the rectangle to test for visibility.

height
Int32

要测试其可见性的矩形的高度。Height of the rectangle to test for visibility.

返回

Boolean

如果 xywidthheight 参数定义的矩形包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the rectangle defined by the x, y, width, and height parameters is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个矩形的位置和大小,一个矩形位于剪辑区域内,一个在外部。Creates the location and size of two rectangles, one inside the clipping region and one outside.

  • 测试每个矩形的可见性并仅绘制可见的矩形。Tests each of the rectangles for visibility and draws only the visible one.

结果为一个小的红色矩形,位于剪辑区域内。The result is one small red rectangle, which is within the clip region.

public:
   void IsVisible4Int( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of rectangles.
      int x1 = 100;
      int y1 = 100;
      int width1 = 20;
      int height1 = 20;
      int x2 = 200;
      int y2 = 200;
      int width2 = 20;
      int height2 = 20;

      // If rectangle is visible, fill it.
      if ( e->Graphics->IsVisible( x1, y1, width1, height1 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), x1, y1, width1, height1 );
      }

      if ( e->Graphics->IsVisible( x2, y2, width2, height2 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), x2, y2, width2, height2 );
      }
   }
private void IsVisible4Int(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of rectangles.
    int x1 = 100;
    int y1 = 100;
    int width1 = 20;
    int height1 = 20;
    int x2 = 200;
    int y2 = 200;
    int width2 = 20;
    int height2 = 20;

    // If rectangle is visible, fill it.
    if (e.Graphics.IsVisible(x1, y1, width1, height1))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Red), x1, y1, width1, height1);
    }
    if (e.Graphics.IsVisible(x2, y2, width2, height2))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Blue), x2, y2, width2, height2);
    }
}
Private Sub IsVisible4Int(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of rectangles.
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim width1 As Integer = 20
    Dim height1 As Integer = 20
    Dim x2 As Integer = 200
    Dim y2 As Integer = 200
    Dim width2 As Integer = 20
    Dim height2 As Integer = 20

    ' If rectangle is visible, fill it.
    If e.Graphics.IsVisible(x1, y1, width1, height1) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Red), x1, y1, _
        width1, height1)
    End If
    If e.Graphics.IsVisible(x2, y2, width2, height2) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Blue), x2, y2, _
        width2, height2)
    End If
End Sub

适用于

IsVisible(Single, Single, Single, Single)

指示由一对坐标、一个宽度和一个高度指定的矩形是否包含在此 Graphics 的可见剪辑区域内。Indicates whether the rectangle specified by a pair of coordinates, a width, and a height is contained within the visible clip region of this Graphics.

public:
 bool IsVisible(float x, float y, float width, float height);
public bool IsVisible (float x, float y, float width, float height);
member this.IsVisible : single * single * single * single -> bool
Public Function IsVisible (x As Single, y As Single, width As Single, height As Single) As Boolean

参数

x
Single

要测试其可见性的矩形的左上角的 x 坐标。The x-coordinate of the upper-left corner of the rectangle to test for visibility.

y
Single

要测试其可见性的矩形的左上角的 y 坐标。The y-coordinate of the upper-left corner of the rectangle to test for visibility.

width
Single

要测试其可见性的矩形的宽度。Width of the rectangle to test for visibility.

height
Single

要测试其可见性的矩形的高度。Height of the rectangle to test for visibility.

返回

Boolean

如果 xywidthheight 参数定义的矩形包含在此 Graphics 的可见剪辑区域内,则为 true;否则为 falsetrue if the rectangle defined by the x, y, width, and height parameters is contained within the visible clip region of this Graphics; otherwise, false.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 使用创建矩形剪辑区域,并将其设置为该窗体图形对象的剪辑区域 ReplaceCreates a rectangular clipping region and sets it as the clipping region for the graphics object of the form using Replace.

  • 创建两个矩形的位置和大小,一个矩形位于剪辑区域内,一个在外部。Creates the location and size of two rectangles, one inside the clipping region and one outside.

  • 测试每个矩形的可见性并仅绘制可见的矩形。Tests each of the rectangles for visibility and draws only the visible one.

结果为一个小的红色矩形,位于剪辑区域内。The result is one small red rectangle, which is within the clip region.

public:
   void IsVisible4Float( PaintEventArgs^ e )
   {
      // Set clip region.
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(50,50,100,100) );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Set up coordinates of rectangles.
      float x1 = 100.0F;
      float y1 = 100.0F;
      float width1 = 20.0F;
      float height1 = 20.0F;
      float x2 = 200.0F;
      float y2 = 200.0F;
      float width2 = 20.0F;
      float height2 = 20.0F;

      // If rectangle is visible, fill it.
      if ( e->Graphics->IsVisible( x1, y1, width1, height1 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), x1, y1, width1, height1 );
      }

      if ( e->Graphics->IsVisible( x2, y2, width2, height2 ) )
      {
         e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), x2, y2, width2, height2 );
      }
   }
private void IsVisible4Float(PaintEventArgs e)
{

    // Set clip region.
    Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Set up coordinates of rectangles.
    float x1 = 100.0F;
    float y1 = 100.0F;
    float width1 = 20.0F;
    float height1 = 20.0F;
    float x2 = 200.0F;
    float y2 = 200.0F;
    float width2 = 20.0F;
    float height2 = 20.0F;

    // If rectangle is visible, fill it.
    if (e.Graphics.IsVisible(x1, y1, width1, height1))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Red), x1, y1, width1, height1);
    }
    if (e.Graphics.IsVisible(x2, y2, width2, height2))
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Blue), x2, y2, width2, height2);
    }
}
Private Sub IsVisible4Float(ByVal e As PaintEventArgs)

    ' Set clip region.
    Dim clipRegion As New [Region](New Rectangle(50, 50, 100, 100))
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Set up coordinates of rectangles.
    Dim x1 As Single = 100.0F
    Dim y1 As Single = 100.0F
    Dim width1 As Single = 20.0F
    Dim height1 As Single = 20.0F
    Dim x2 As Single = 200.0F
    Dim y2 As Single = 200.0F
    Dim width2 As Single = 20.0F
    Dim height2 As Single = 20.0F

    ' If rectangle is visible, fill it.
    If e.Graphics.IsVisible(x1, y1, width1, height1) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Red), x1, y1, _
        width1, height1)
    End If
    If e.Graphics.IsVisible(x2, y2, width2, height2) Then
        e.Graphics.FillRectangle(New SolidBrush(Color.Blue), x2, y2, _
        width2, height2)
    End If
End Sub

适用于