我正在寻求有关 drawpolygon 方法的帮助。我没有任何运气可以工作。想做 5 个三角形,大小相同,彼此相邻。问题是我必须使用 do-while 循环。感谢您花时间帮助我!!
问问题
575 次
2 回答
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 文档。
你是否在循环中做任何事情都没有关系,取决于如何。如果这不能解决您的问题,请发布您的代码以便为您提供更多帮助。
带有循环的示例:
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
于 2013-02-27T08:37:26.390 回答
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 替换为您想要使用的任何点数组。
于 2013-02-27T18:38:31.960 回答