指定した Brush と Width を使用して、Pen クラスの新しいインスタンスを初期化します。
名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
'宣言
Public Sub New ( _
brush As Brush, _
width As Single _
)
'使用
Dim brush As Brush
Dim width As Single
Dim instance As New Pen(brush, width)
public Pen (
Brush brush,
float width
)
public:
Pen (
Brush^ brush,
float width
)
public Pen (
Brush brush,
float width
)
public function Pen (
brush : Brush,
width : float
)
パラメータ
- width
新しい Pen の幅。
例外
例外の種類 | 条件 |
---|---|
brush が null 参照 (Visual Basic では Nothing) です。 |
解説
Brush は brush パラメータで指定された色に、Width プロパティは width パラメータで指定された値に、単位は World にそれぞれ設定されます。
brush パラメータは、この Pen の Color プロパティも指定します。
width に 0 を指定した場合は、1 が指定されたものと見なされて Pen の描画が行われます。
使用例
次のコード例では、Pen を作成し、Pen で StartCap プロパティおよび EndCap プロパティを設定することの効果を示します。
この例は、Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、フォームの Paint イベントを処理するときに PaintEventArgs の e を渡して ShowStartAndEndCaps
メソッドを呼び出します。
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Dim buttonGraphics As Graphics = Button3.CreateGraphics()
Dim myPen As Pen = New Pen(Color.ForestGreen, 4.0F)
myPen.DashStyle = Drawing2D.DashStyle.DashDotDot
Dim theRectangle As Rectangle = Button3.ClientRectangle
theRectangle.Inflate(-2, -2)
buttonGraphics.DrawRectangle(myPen, theRectangle)
buttonGraphics.Dispose()
myPen.Dispose()
End Sub
private void Button3_Click(System.Object sender, System.EventArgs e)
{
Graphics buttonGraphics = Button3.CreateGraphics();
Pen myPen = new Pen(Color.ForestGreen, 4.0F);
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
Rectangle theRectangle = Button3.ClientRectangle;
theRectangle.Inflate(-2, -2);
buttonGraphics.DrawRectangle(myPen, theRectangle);
buttonGraphics.Dispose();
myPen.Dispose();
}
private:
void Button3_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Graphics^ buttonGraphics = Button3->CreateGraphics();
Pen^ myPen = gcnew Pen( Color::ForestGreen,4.0F );
myPen->DashStyle = System::Drawing::Drawing2D::DashStyle::DashDotDot;
Rectangle theRectangle = Button3->ClientRectangle;
theRectangle.Inflate( -2, -2 );
buttonGraphics->DrawRectangle( myPen, theRectangle );
delete buttonGraphics;
delete myPen;
}
private void button3_Click(Object sender, System.EventArgs e)
{
Graphics buttonGraphics = button3.CreateGraphics();
Pen myPen = new Pen(Color.get_ForestGreen(), 4.0F);
myPen.set_DashStyle(System.Drawing.Drawing2D.DashStyle.DashDotDot);
Rectangle theRectangle = button3.get_ClientRectangle();
theRectangle.Inflate(-2, -2);
buttonGraphics.DrawRectangle(myPen, theRectangle);
buttonGraphics.Dispose();
myPen.Dispose();
} //button3_Click
プラットフォーム
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