迅速掌握VB.NET操作GDI圖形
VB.NET編程語言在對圖形的操作上可以體現(xiàn)出其全面和靈活性。我們可以通過VB.NET操作GDI圖形的相關操作方法和實現(xiàn)的功能來對這一方面的知識進行一個系統(tǒng)的認識,了解VB.NET在操作中的簡便靈活性。#t#
下面的例子通過重載Form1窗體的OnPaint()方法繪制GDI圖形
- Protected Overrides Sub onpaint
(ByVal e As System.Windows.
Forms.PaintEventArgs)
注釋://///////////VB.NET操作GDI圖形繪制任意直線
- 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)
注釋:////////////VB.NET操作GDI圖形文本表示
- 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)
注釋:////////////VB.NET操作GDI圖形平面繪制
- 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
VB.NET操作GDI圖形的各種操作技巧就為大家介紹到這里。