Option Explicit
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
End Sub
Private Sub DrawLine()
Dim i As Single
Dim Angle As Single
Cls
If Me.ScaleHeight = 0 Then
Exit Sub
End If
If Me.WindowState = vbMinimized Then
Exit Sub
End If
Angle = Atn(Me.ScaleWidth / Me.ScaleHeight)
For i = 0 To Sqr(Me.ScaleWidth * Me.ScaleWidth + Me.ScaleHeight * Me.ScaleHeight)
PSet (i * Sin(Angle), i * Cos(Angle))
Next
End Sub
Private Sub Form_Resize()
Call DrawLine
End Sub
Open a new vb project (Standard Executable) and copy/paste this code.
Option Explicit
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
End Sub
Private Sub DrawLine()
Dim i As Single
Dim Angle As Single
Cls
If Me.ScaleHeight = 0 Then
Exit Sub
End If
If Me.WindowState = vbMinimized Then
Exit Sub
End If
Angle = Atn(Me.ScaleWidth / Me.ScaleHeight)
For i = 0 To Sqr(Me.ScaleWidth * Me.ScaleWidth + Me.ScaleHeight * Me.ScaleHeight)
PSet (i * Sin(Angle), i * Cos(Angle))
Next
End Sub
Private Sub Form_Resize()
Call DrawLine
End Sub
Private Sub circleRoutine(aX As Single, aY As Single, Radius As Single, Steps As Single)
Dim currAngleX As Single
Dim i As Integer
aX = aX - Radius * 1 / Steps
For currAngleX = 0 To Rad(360) Step Steps
aX = aX + Radius * Sin(currAngleX)
aY = aY + Radius * Cos(currAngleX)
Me.PSet (aX, aY)
Next currAngleX
End Sub
Private Sub circleRoutine(aX As Single, aY As Single, Radius As Single, Steps As Single)
Dim currAngleX As Single
Dim i As Integer
aX = aX - Radius * 1 / Steps
For currAngleX = 0 To Rad(360) Step Steps
aX = aX + Radius * Sin(currAngleX)
aY = aY + Radius * Cos(currAngleX)
Me.PSet (aX, aY)
Next currAngleX
End Sub
Private Sub DrawCircle(ByVal X As Single, ByVal Y As Single, ByVal Diameter As Single, ByVal PointsToDraw As Long)
Dim Angle As Single
For Angle = 0 To 2 * 3.14159 Step (2 * 3.14159) / PointsToDraw
Me.PSet (X + Diameter * Sin(Angle) / 2, Y + Diameter * Cos(Angle) / 2), vbRed
Next
End Sub
您应该知道,您可以使用 Circle 函数来代替。上面的代码可以替换为:
Me.Circle (X,Y), Diameter / 2, vbRed
PSet 是一种相对较慢的绘制图形的方法,特别是当已经有一个可以使用的内置函数时。
Private Sub DrawCircle(ByVal X As Single, ByVal Y As Single, ByVal Diameter As Single, ByVal PointsToDraw As Long)
Dim Angle As Single
For Angle = 0 To 2 * 3.14159 Step (2 * 3.14159) / PointsToDraw
Me.PSet (X + Diameter * Sin(Angle) / 2, Y + Diameter * Cos(Angle) / 2), vbRed
Next
End Sub
You should be aware that there is a Circle function that you can use instead. The code above could be replaced with:
Me.Circle (X,Y), Diameter / 2, vbRed
PSet is a relatively slow way to draw graphics, especially when there is already a built-in function you can use instead.
发布评论
评论(3)
打开一个新的 vb 项目(标准可执行文件)并复制/粘贴此代码。
Open a new vb project (Standard Executable) and copy/paste this code.
您应该知道,您可以使用 Circle 函数来代替。上面的代码可以替换为:
PSet 是一种相对较慢的绘制图形的方法,特别是当已经有一个可以使用的内置函数时。
You should be aware that there is a Circle function that you can use instead. The code above could be replaced with:
PSet is a relatively slow way to draw graphics, especially when there is already a built-in function you can use instead.