我正在尝试编写一个程序,围绕表单中心绘制圆圈(创建一个更大的圆圈),我注意到它不是真的有效,圆圈是在错误的坐标,下面的图片解释了我的意思意味着
输入为3时:
输入为10时:
如你所见,圆圈不均匀,这是代码:
Dim center As Integer = Convert.ToInt32(Me.Width / 2)
Dim angels As Integer = 360 / deviceCount
TextBox1.Text = deviceCount
Dim i As Integer
For i = 1 To deviceCount
e.Graphics.DrawEllipse(Pens.Red, Convert.ToInt32(center + 275 * Math.Cos(i * angels)) - 25, Convert.ToInt32(center + 275 * Math.Sin(i * angels)) - 25, 50, 50)
Next
*注意:表单为600 * 600,而deviceCount是文本框中的数字(圆圈数)
提前感谢!
编辑:
答案 0 :(得分:3)
懒惰的方式。
Private Sub DrawCircles(ByVal Graphics As Graphics, ByVal Number As Integer, ByVal Radius As Integer)
Dim Center = New Point(Me.ClientSize.Width \ 2, Me.ClientSize.Height \ 2)
Dim BigRadius = Math.Min(Center.X, Center.Y) - Radius
Dim CurrentState = Graphics.Save()
Graphics.ResetTransform()
Graphics.TranslateTransform(Center.X, Center.Y)
Graphics.DrawEllipse(Pens.Blue, -BigRadius, -BigRadius, BigRadius * 2, BigRadius * 2)
For i As Integer = 1 To Number
Graphics.RotateTransform(360 \ Number)
Graphics.DrawEllipse(Pens.Red, 0, -BigRadius - Radius, Radius * 2, Radius * 2)
Next
Graphics.Restore(CurrentState)
End Sub