VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
線を描画するには、必ずPenオブジェクトが必要となります。またPenオブジェクトは使用後は必ずDisposeで破棄する必要があります。
Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint 'グラフィックオブジェクトを取得する Dim GR As Graphics = e.Graphics 'Color.Blueでペンを作成 Dim Pen1 As New Pen(Color.Blue) 'Color.Red,幅3でペンを作成 Dim Pen2 As New Pen(Color.Red, 3) 'Brushes.Aquaでペンを作成 Dim Pen3 As New Pen(Brushes.Aqua) 'Brushes.DarkBlue,幅5でペンを作成 Dim Pen4 As New Pen(Brushes.DarkBlue, 5) '各ペンで線を描画する GR.DrawLine(Pen1, 10, 10, 110, 10) GR.DrawLine(Pen2, 10, 20, 110, 20) GR.DrawLine(Pen3, 10, 30, 110, 30) GR.DrawLine(Pen4, 10, 40, 110, 40) '各Penオブジェクトを破棄する Pen1.Dispose() Pen2.Dispose() Pen3.Dispose() Pen4.Dispose() 'Graphicsオブジェクト破棄する GR.Dispose() End Sub