Graphics.Clip 属性

获取或设置 Region,该对象限定此 Graphics 的绘图区域。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Property Clip As Region
用法
Dim instance As Graphics
Dim value As Region

value = instance.Clip

instance.Clip = value
public Region Clip { get; set; }
public:
property Region^ Clip {
    Region^ get ();
    void set (Region^ value);
}
/** @property */
public Region get_Clip ()

/** @property */
public void set_Clip (Region value)
public function get Clip () : Region

public function set Clip (value : Region)

属性值

一个 Region,它限定此 Graphics 当前可用的绘图区域。

备注

为确定剪辑区域是否为无限,应检索 Clip 属性并调用其 IsInfinite 方法。

示例

下面的代码示例阐释了如何使用 Clip 属性。此示例是针对使用 Windows 窗体而设计的。将代码粘贴到一个窗体中,然后在处理窗体的 Paint 事件时调用 SetAndFillClip 方法,并传递 e 作为 PaintEventArgs

Private Sub SetAndFillClip(ByVal e As PaintEventArgs)

    ' Set the Clip property to a new region.
    e.Graphics.Clip = New Region(New Rectangle(10, 10, 100, 200))

    ' Fill the region.
    e.Graphics.FillRegion(Brushes.LightSalmon, e.Graphics.Clip)

    ' Demonstrate the clip region by drawing a string
    ' at the outer edge of the region.
    e.Graphics.DrawString("Outside of Clip", _
        New Font("Arial", 12.0F, FontStyle.Regular), _
        Brushes.Black, 0.0F, 0.0F)

End Sub
private void SetAndFillClip(PaintEventArgs e)
{

    // Set the Clip property to a new region.
    e.Graphics.Clip = new Region(new Rectangle(10, 10, 100, 200));

    // Fill the region.
    e.Graphics.FillRegion(Brushes.LightSalmon, e.Graphics.Clip);

    // Demonstrate the clip region by drawing a string
    // at the outer edge of the region.
    e.Graphics.DrawString("Outside of Clip", new Font("Arial", 
        12.0F, FontStyle.Regular), Brushes.Black, 0.0F, 0.0F);

}
private:
   void SetAndFillClip( PaintEventArgs^ e )
   {
      // Set the Clip property to a new region.
      e->Graphics->Clip = gcnew System::Drawing::Region( Rectangle(10,10,100,200) );

      // Fill the region.
      e->Graphics->FillRegion( Brushes::LightSalmon, e->Graphics->Clip );

      // Demonstrate the clip region by drawing a string
      // at the outer edge of the region.
      e->Graphics->DrawString( "Outside of Clip", gcnew System::Drawing::Font( "Arial",12.0F,FontStyle::Regular ), Brushes::Black, 0.0F, 0.0F );
   }
private void SetAndFillClip(PaintEventArgs e)
{
    // Set the Clip property to a new region.
    e.get_Graphics().set_Clip(new Region(new Rectangle(10, 10, 100, 200)));

    // Fill the region.
    e.get_Graphics().FillRegion(Brushes.get_LightSalmon(),
        e.get_Graphics().get_Clip());

    // Demonstrate the clip region by drawing a string
    // at the outer edge of the region.
    e.get_Graphics().DrawString("Outside of Clip", 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.get_Black(), 0, 0);
} //SetAndFillClip

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Graphics 类
Graphics 成员
System.Drawing 命名空间