我正在寻找drawpolygon方法的帮助。我没有运气得到任何工作。期待做5个相同大小的三角形,彼此相邻。问题是我必须使用do-while循环。感谢您抽出宝贵时间来帮助我!!
答案 0 :(得分:2)
只需定义数组中的点,然后用笔写下它们:
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 Documentation。
如果你在循环中做任何事情都没关系,取决于如何。如果这不能解决您的问题,请发布您的代码,以便为您提供更多帮助。
循环示例:
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
答案 1 :(得分:0)
我实际上没有对这种结构进行过测试,但它已经完成了一个工作项目;我怀疑它会起作用,而且这些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替换为您想要使用的任何点数。