簡體   English   中英

使用do-while循環的Visual Basic drawpolygon方法?

[英]Visual Basic drawpolygon method using a do-while loop?

我正在尋找drawpolygon方法的幫助。 我沒有運氣得到任何工作。 期待做5個相同大小的三角形,彼此相鄰。 問題是我必須使用do-while循環。 感謝您抽出寶貴時間來幫助我!!

只需定義數組中的點,然后用筆寫下它們:

Dim blackPen As New Pen(Color.Black, 3)

Dim point1 As New Point(50, 50)
Dim point2 As New Point(100, 25)
Dim curvePoints As Point() = {point1, point2}

Me.CreateGraphics.DrawPolygon(blackPen, curvePoints)

請查看有關它的MSDN文檔

如果你在循環中做任何事情並不重要,取決於如何。 如果這不能解決您的問題,請發布您的代碼,以便為您提供更多幫助。

循環示例:

Do While i < 3
    point1 As New Point(50 + i * 10, 50)
    point2 As New Point(100 + i * 7, 25)

    curvePoints = {point1, point2}
    Me.CreateGraphics.DrawPolygon(blackPen, curvePoints)
    i += 1
Loop

我實際上沒有對這種結構進行測試,但它已經完成了一個工作項目; 我懷疑它會起作用,而且這些GDI +中的一些東西在第一次拾取時非常蹩腳。

Public Class Form1
Private subject As Image

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    If Not subject Is Nothing Then
        Dim g As Graphics = e.Graphics
        g.DrawImage(subject, New Point(1, 1))
    End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim tempBM As New Bitmap(subject)
    tempBM.SetResolution(subject.HorizontalResolution, subject.VerticalResolution)
    Using g As Graphics = Graphics.FromImage(tempBM)
         g.DrawPolygon(OutlinePen, Polygon.GetPoints)
    End Using
    subject = tempBM
    Invalidate()
End Sub
End Class

哦,Polygon是我的代碼中的一個你不會擁有的類。 但只需將Polygon.GetPoints替換為您想要使用的任何點數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM