Graphics.IsVisible 方法

定义

指示由一对坐标指定的点是否包含在此 Graphics的可见剪辑区域中。

重载

IsVisible(Single, Single, Single, Single)

指示由一对坐标、宽度和高度指定的矩形是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Int32, Int32, Int32, Int32)

指示由一对坐标、宽度和高度指定的矩形是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Int32, Int32)

指示由一对坐标指定的点是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Single, Single)

指示由一对坐标指定的点是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Rectangle)

指示由 Rectangle 结构指定的矩形是否包含在此 Graphics的可见剪辑区域中。

IsVisible(PointF)

指示指定的 PointF 结构是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Point)

指示指定的 Point 结构是否包含在此 Graphics的可见剪辑区域中。

IsVisible(RectangleF)

指示由 RectangleF 结构指定的矩形是否包含在此 Graphics的可见剪辑区域中。

IsVisible(Single, Single, Single, Single)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由一对坐标、宽度和高度指定的矩形是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (float x, float y, float width, float height);

参数

x
Single

要测试可见性的矩形左上角的 x 坐标。

y
Single

要测试可见性的矩形左上角的 y 坐标。

width
Single

要测试可见性的矩形的宽度。

height
Single

要测试可见性的矩形的高度。

返回

如果 xywidthheight 参数定义的矩形包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个矩形的位置和大小,一个在剪辑区域内,一个在外部。

  • 测试每个矩形的可见性,并仅绘制可见的矩形。

结果是一个小红色矩形,该矩形位于剪辑区域中。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(Int32, Int32, Int32, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由一对坐标、宽度和高度指定的矩形是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (int x, int y, int width, int height);

参数

x
Int32

要测试可见性的矩形左上角的 x 坐标。

y
Int32

要测试可见性的矩形左上角的 y 坐标。

width
Int32

要测试可见性的矩形的宽度。

height
Int32

要测试可见性的矩形的高度。

返回

如果 xywidthheight 参数定义的矩形包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个矩形的位置和大小,一个在剪辑区域内,一个在外部。

  • 测试每个矩形的可见性,并仅绘制可见的矩形。

结果是一个小红色矩形,该矩形位于剪辑区域中。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(Int32, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由一对坐标指定的点是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (int x, int y);

参数

x
Int32

要测试可见性的点的 x 坐标。

y
Int32

要测试可见性的点的 y 坐标。

返回

如果 xy 参数定义的点包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个点,一个在剪辑区域内部,一个在外部。

  • 测试每个点的可见性,并仅绘制可见点。

结果是一个位于剪辑区域中的一个小红色圆圈。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(Single, Single)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由一对坐标指定的点是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (float x, float y);

参数

x
Single

要测试可见性的点的 x 坐标。

y
Single

要测试可见性的点的 y 坐标。

返回

如果 xy 参数定义的点包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个点,一个在剪辑区域内部,一个在外部。

  • 测试每个点的可见性,并仅绘制可见点。

结果是一个位于剪辑区域中的一个小红色圆圈。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(Rectangle)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由 Rectangle 结构指定的矩形是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (System.Drawing.Rectangle rect);

参数

rect
Rectangle

Rectangle 结构来测试可见性。

返回

如果 rect 参数指定的矩形包含在此 Graphics的可见剪辑区域中,则 true ;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个矩形的位置和大小,一个在剪辑区域内,一个在外部。

  • 测试每个矩形的可见性,并仅绘制可见的矩形。

结果是一个小红色矩形,该矩形位于剪辑区域中。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(PointF)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示指定的 PointF 结构是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (System.Drawing.PointF point);

参数

point
PointF

PointF 结构来测试可见性。

返回

如果 point 参数指定的点包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建一个矩形剪辑区域,并使用 Replace将其设置为窗体图形的剪裁区域。

  • 创建两个点,一个在剪辑区域内部,一个在外部。

  • 测试每个点的可见性,并仅绘制可见点。

结果是一个位于剪辑区域中的一个小红色圆圈。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(Point)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示指定的 Point 结构是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (System.Drawing.Point point);

参数

point
Point

Point 结构来测试可见性。

返回

如果 point 参数指定的点包含在此 Graphics的可见剪辑区域中,则 true;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个点,一个在剪辑区域内部,一个在外部。

  • 测试每个点的可见性,并仅绘制可见点。

结果是一个位于剪辑区域中的一个小红色圆圈。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

IsVisible(RectangleF)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

指示由 RectangleF 结构指定的矩形是否包含在此 Graphics的可见剪辑区域中。

C#
public bool IsVisible (System.Drawing.RectangleF rect);

参数

rect
RectangleF

RectangleF 结构来测试可见性。

返回

如果 rect 参数指定的矩形包含在此 Graphics的可见剪辑区域中,则 true ;否则,false

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建矩形剪辑区域,并使用 Replace将其设置为窗体图形对象的剪裁区域。

  • 创建两个矩形,一个在剪辑区域内部,一个在外部。

  • 测试每个矩形的可见性,并仅绘制可见的矩形。

结果是一个小红色矩形,该矩形位于剪辑区域中。

C#
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);
    }
}

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9