Graphics.TranslateClip 方法

定义

按水平方向和垂直方向的指定量转换此 Graphics 的剪辑区域。

重载

TranslateClip(Int32, Int32)

按水平方向和垂直方向的指定量转换此 Graphics 的剪辑区域。

TranslateClip(Single, Single)

按水平方向和垂直方向的指定量转换此 Graphics 的剪辑区域。

TranslateClip(Int32, Int32)

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

按水平方向和垂直方向的指定量转换此 Graphics 的剪辑区域。

C#
public void TranslateClip (int dx, int dy);

参数

dx
Int32

翻译的 x 坐标。

dy
Int32

翻译的 y 坐标。

示例

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

  • 为剪裁区域创建一个矩形。

  • 将剪辑区域设置为矩形。

  • 按矢量(50,50)转换剪辑区域。

  • 用纯黑色画笔填充大矩形。

结果是已转换的小型黑色矩形。

C#
private void TranslateClipInt(PaintEventArgs e)
{

    // Create rectangle for clipping region.
    Rectangle clipRect = new Rectangle(0, 0, 100, 100);

    // Set clipping region of graphics to rectangle.
    e.Graphics.SetClip(clipRect);

    // Translate clipping region.
    int dx = 50;
    int dy = 50;
    e.Graphics.TranslateClip(dx, dy);

    // Fill rectangle to demonstrate translated clip region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}

适用于

.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

TranslateClip(Single, Single)

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

按水平方向和垂直方向的指定量转换此 Graphics 的剪辑区域。

C#
public void TranslateClip (float dx, float dy);

参数

dx
Single

翻译的 x 坐标。

dy
Single

翻译的 y 坐标。

示例

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

  • 为剪裁区域创建一个矩形。

  • 将剪辑区域设置为矩形。

  • 按矢量(50.0F、50.0F)转换剪辑区域。

  • 用纯黑色画笔填充大矩形。

结果是已转换的小型黑色矩形。

C#
private void TranslateClipFloat(PaintEventArgs e)
{

    // Create rectangle for clipping region.
    RectangleF clipRect = new RectangleF(0.0F, 0.0F, 100.0F, 100.0F);

    // Set clipping region of graphics to rectangle.
    e.Graphics.SetClip(clipRect);

    // Translate clipping region.
    float dx = 50.0F;
    float dy = 50.0F;
    e.Graphics.TranslateClip(dx, dy);

    // Fill rectangle to demonstrate translated clip region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}

适用于

.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