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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
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 Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
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 Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出一對座標所指定的點是否包含在這個 Graphics的可見剪輯區域內。

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

參數

x
Int32

要測試可見性之點的 X 座標。

y
Int32

要測試可見性之點的 Y 座標。

傳回

如果 xy 參數定義的點包含在這個 Graphics的可見剪輯區域內,true;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出一對座標所指定的點是否包含在這個 Graphics的可見剪輯區域內。

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

參數

x
Single

要測試可見性之點的 X 座標。

y
Single

要測試可見性之點的 Y 座標。

傳回

如果 xy 參數定義的點包含在這個 Graphics的可見剪輯區域內,true;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出 Rectangle 結構所指定的矩形是否包含在這個 Graphics的可見剪輯區域內。

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

參數

rect
Rectangle

Rectangle 結構,以測試可見度。

傳回

如果 rect 參數指定的矩形包含在這個 Graphics的可見剪輯區域內,true ;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出指定的 PointF 結構是否包含在這個 Graphics的可見剪輯區域內。

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

參數

point
PointF

PointF 結構,以測試可見度。

傳回

如果 point 參數所指定的點包含在這個 Graphics的可見剪輯區域內,true ;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出指定的 Point 結構是否包含在這個 Graphics的可見剪輯區域內。

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

參數

point
Point

Point 結構,以測試可見度。

傳回

如果 point 參數所指定的點包含在這個 Graphics的可見剪輯區域內,true ;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

指出 RectangleF 結構所指定的矩形是否包含在這個 Graphics的可見剪輯區域內。

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

參數

rect
RectangleF

RectangleF 結構,以測試可見度。

傳回

如果 rect 參數指定的矩形包含在這個 Graphics的可見剪輯區域內,true ;否則,false

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 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