共用方式為


Pen.Width 屬性

定義

以繪圖物件為單位來取得或設定此PenGraphics寬度。

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 的 。

範例

以下程式碼範例展示了將 和 LineJoin 屬性設定WidthPen

此範例設計用於 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

備註

你可以利用物件的PageUnit特性來取得其度量Graphics單位。 度量單位通常是像素。 A Width 為 0 時,抽獎結果 Pen 就像 Width 1 一樣。

適用於