在vb.net中绘制一个septagon

时间:2011-03-28 15:57:01

标签: vb.net winforms polygon

有没有人有能在vb.net中绘制等边septagon的代码?

所有方面和角度都必须相等。

由于

2 个答案:

答案 0 :(得分:0)

不,但是如果你想到60分钟的钟面,每8.5分钟标记一个7边形状的一点。

答案 1 :(得分: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)