VB.NET中使用GDI畫圖具體應用。

來源:互聯網
上載者:User
下面的例子通過重載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

這些是我自己實驗出來的,當然了,還有好多,我只是開了一個頭,大家要是發現什麼好東東,別忘了通知一下:)

相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。