SystemPens 类

SystemPens 类的每个属性都是一个 Pen,它是 Windows 显示元素的颜色,宽度为 1 个像素。

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

语法

声明
Public NotInheritable Class SystemPens
用法
Dim instance As SystemPens
public sealed class SystemPens
public ref class SystemPens sealed
public final class SystemPens
public final class SystemPens

示例

下面的代码示例使用多个为这些类型定义的重载运算符创建磅值和大小。它还演示如何使用 SystemPens 类。

此示例是针对使用 Windows 窗体而设计的。创建一个包含名为 subtractButtonButton 的窗体。将代码粘贴到此窗体中,然后从该窗体的 Paint 事件处理方法中调用 CreatePointsAndSizes 方法,将 e 作为 PaintEventArgs 传递。

Private Sub CreatePointsAndSizes(ByVal e As PaintEventArgs)

    ' Create the starting point.
    Dim startPoint As New Point(subtractButton.Size)

    ' Use the addition operator to get the end point.
    Dim endPoint As Point = Point.op_Addition(startPoint, _
        New Size(140, 150))

    ' Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint)

    ' Convert the starting point to a size and compare it to the
    ' subtractButton size.  
    Dim buttonSize As Size = Point.op_Explicit(startPoint)
    If (Size.op_Equality(buttonSize, subtractButton.Size)) Then

        ' If the sizes are equal, tell the user.
        e.Graphics.DrawString("The sizes are equal.", _
            New Font(Me.Font, FontStyle.Italic), _
            Brushes.Indigo, 10.0F, 65.0F)
    End If

End Sub
private void CreatePointsAndSizes(PaintEventArgs e)
{

    // Create the starting point.
    Point startPoint = new Point(subtractButton.Size);

    // Use the addition operator to get the end point.
    Point endPoint = startPoint + new Size(140, 150);

    // Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint);

    // Convert the starting point to a size and compare it to the
    // subtractButton size.  
    Size buttonSize = (Size)startPoint;
    if (buttonSize == subtractButton.Size)

        // If the sizes are equal, tell the user.
    {
        e.Graphics.DrawString("The sizes are equal.", 
            new Font(this.Font, FontStyle.Italic), 
            Brushes.Indigo, 10.0F, 65.0F);
    }

}
void CreatePointsAndSizes( PaintEventArgs^ e )
{
   // Create the starting point.
   Point startPoint = Point(subtractButton->Size);
   
   // Use the addition operator to get the end point.
   Point endPoint = startPoint + System::Drawing::Size( 140, 150 );
   
   // Draw a line between the points.
   e->Graphics->DrawLine( SystemPens::Highlight, startPoint, endPoint );
   
   // Convert the starting point to a size and compare it to the
   // subtractButton size.  
   System::Drawing::Size buttonSize = (System::Drawing::Size)startPoint;
   if ( buttonSize == subtractButton->Size )
   {
      e->Graphics->DrawString( "The sizes are equal.", gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), Brushes::Indigo, 10.0F, 65.0F );
   }
}
private void CreatePointsAndSizes(PaintEventArgs e)
{
    // Create the starting point.
    Point startPoint = new Point(subtractButton.get_Size());

    // Use the addition operator to get the end point.
    Point endPoint = Point.op_Addition(startPoint, new Size(140, 150));

    // Draw a line between the points.
    e.get_Graphics().DrawLine(SystemPens.get_Highlight(), startPoint, 
        endPoint);

    // Convert the starting point to a size and compare it to the
    // subtractButton size.  
    Size buttonSize = new Size(startPoint);

    if (buttonSize.Equals(subtractButton.get_Size())) {
        // If the sizes are equal, tell the user.
        e.get_Graphics().DrawString("The sizes are equal.", 
            new Font(this.get_Font(), FontStyle.Italic), 
            Brushes.get_Indigo(), 10, 65);
    }
} //CreatePointsAndSizes

继承层次结构

System.Object
  System.Drawing.SystemPens

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、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

请参见

参考

SystemPens 成员
System.Drawing 命名空间