下面的例子通過重載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!"
dim solidbrush as solidbrush = new solidbrush(color.red)
dim pr as pointf = new pointf(100, 10)
e.graphics.drawstring(text, font, solidbrush, pr)
'////////////平面繪制
dim rec as rectanglef = new rectanglef(10, 10, 200, 100)
g.drawpie(mypen, rec, 150, 150)
'///////////封閉圖形,0.7應該是個圓
g.drawclosedcurve(mypen, curvepoints, 0.7, drawing.drawing2d.fillmode.alternate)
'///////////大家自己試試看吧
g.drawarc(mypen, 300, 300, 200, 200, 100, 100)
g.drawcurve(mypen, curvepoints)
g.drawbezier(mypen, 50, 50, 100, 50, 100, 100, 50, 100)
g.drawbeziers(mypen, curvepoints)
'//////////這可是一個圓
dim rec1 as rectanglef = new rectanglef(10, 10, 100, 100)
g.drawellipse(mypen, rec1)
'//////////這是一個橢圓
dim rec2 as rectanglef = new rectanglef(10, 10, 200, 100)
g.drawellipse(mypen, rec2)
end sub
這些是我自己試驗出來的,當然了,還有好多,我只是開了一個頭,大家要是發現什么好東東,別忘了通知一下:)