Pen.Width 属性

定义

获取或设置此 Pen 的宽度,以用于绘图的 Graphics 对象为单位。

public:
 property float Width { float get(); void set(float value); };
public float Width { get; set; }
member this.Width : single with get, set
Public Property Width As Single

属性值

Pen 的宽度。

例外

对不可变的 Width(比如由 Pen 类所返回)设置 Pens 属性。

示例

下面的代码示例演示在 上Pen设置 WidthLineJoin 属性的效果。

此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到窗体中,并在处理窗体的 Paint 事件时调用 ShowLineJoin 方法,作为 ePaintEventArgs传递。

private:
   void ShowLineJoin( PaintEventArgs^ e )
   {
      // Create a new pen.
      Pen^ skyBluePen = gcnew Pen( Brushes::DeepSkyBlue );

      // Set the pen's width.
      skyBluePen->Width = 8.0F;

      // Set the LineJoin property.
      skyBluePen->LineJoin = System::Drawing::Drawing2D::LineJoin::Bevel;

      // Draw a rectangle.
      e->Graphics->DrawRectangle( skyBluePen, Rectangle(40,40,150,200) );

      //Dispose of the pen.
      delete skyBluePen;
   }
private void ShowLineJoin(PaintEventArgs e)
{

    // Create a new pen.
    Pen skyBluePen = new Pen(Brushes.DeepSkyBlue);

    // Set the pen's width.
    skyBluePen.Width = 8.0F;

    // Set the LineJoin property.
    skyBluePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;

    // Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, 
        new Rectangle(40, 40, 150, 200));

    //Dispose of the pen.
    skyBluePen.Dispose();
}
Private Sub ShowLineJoin(ByVal e As PaintEventArgs)

    ' Create a new pen.
    Dim skyBluePen As New Pen(Brushes.DeepSkyBlue)

    ' Set the pen's width.
    skyBluePen.Width = 8.0F

    ' Set the LineJoin property.
    skyBluePen.LineJoin = Drawing2D.LineJoin.Bevel

    ' Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, _
        New Rectangle(40, 40, 150, 200))

    'Dispose of the pen.
    skyBluePen.Dispose()

End Sub

注解

可以使用对象的 属性访问对象的GraphicsPageUnit度量单位。 度量单位通常是像素。 如果 Width 为 0, Pen 则会导致绘图,就像 Width 是 1 一样。

适用于