下面的例子通过重载Form1窗体的OnPaint()方法绘制GDI图形
Protected Overrides Sub onpaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'/////////////绘制任意直线
Dim g As Graphics = e.Graphics
Dim mypen As Pen = New Pen(Color.Red, 2)
g.DrawLine(mypen, 100, 100, 10, 10)
'/////////////绘制矩形(任意直线构成的封闭图形)
Dim point1 As PointF = New PointF(100F, 100F)
Dim point2 As PointF = New PointF(200F, 100F)
Dim point3 As PointF = New PointF(200F, 200F)
Dim point4 As PointF = New PointF(100F, 200F)
Dim curvepoints As PointF() = {point1, point2, point3, point4}
g.DrawPolygon(New Pen(Color.Blue, 2), curvepoints)
'////////////文本表示
Dim FFamily As FontFamily = New FontFamily("Arial")
Dim font As Font = New Font(FFamily, "20", FontStyle.Bold, FontStyle.Italic, GraphicsUnit.Pixel)
Dim text As String = "I love you!"