2011-03-28 42 views
2

有沒有人有任何代碼可以在vb.net中繪製等邊七邊形?在vb.net中繪製七邊形

所有的邊和角度都需要相等。

感謝

+0

如何繪製?你使用的是WPF,WinForms,Silverlight還是一些位圖API? – Gabe 2011-03-28 16:02:36

+0

我正在使用winforms – Michael 2011-03-28 16:30:29

回答

0

沒有,但是如果您進行60分鐘想一個鐘面,每個8.5分鐘標誌着您的7邊形的一個點。

0

這裏是畫雙方指定數目的正多邊形的功能:

Sub poly(ByVal center As PointF, ByVal radius As Double, ByVal nSides As Integer, ByVal g As Graphics) 

Dim pts(nSides) As PointF 
Dim Angle As Double = Math.PI * 2/nSides 
Dim i As Integer 
Dim a As Double 

a = Math.PI/2 ' first point on top 
For i = 0 To UBound(pts) 
    pts(i) = center + New Point(radius * Math.Cos(a), -radius * Math.Sin(a)) 
    a = a + Angle 
    Next i 

g.DrawPolygon(Pens.DarkGreen, pts) 
End Sub 

稱呼它,建立一個圖形對象,你想讓它繪製。例如,要將它繪製在PictureBox1中,可以這樣稱呼它:

Dim g As Graphics 

PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) ' new bitmap 
g = Graphics.FromImage(PictureBox1.Image) ' assign graphics object to g 
g.FillRectangle(Brushes.White, 0, 0, PictureBox1.Width, PictureBox1.Height) ' white background 
' draw 7-sided polygon in the center of the picturebox 
poly(New PointF(PictureBox1.Width/2, PictureBox1.Height/2), PictureBox1.Height/3, 7, g)