📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5880
ClientLeft = 60
ClientTop = 345
ClientWidth = 6375
LinkTopic = "Form1"
ScaleHeight = 5880
ScaleWidth = 6375
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "绘制"
Height = 495
Left = 2400
TabIndex = 1
Top = 5280
Width = 1215
End
Begin VB.PictureBox Picture1
Height = 4845
Left = 600
ScaleHeight = 4785
ScaleWidth = 4785
TabIndex = 0
Top = 240
Width = 4845
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'清除picture1内的图形
Picture1.Cls
'Scale方法设定用户坐标系,坐标原点在Picture1中心
Picture1.ScaleMode = 0
Picture1.ScaleMode = 3
Picture1.Scale (-80, 80)-(80, -80)
'设置绘线宽度
Picture1.DrawWidth = 2
'递归绘制正方形
Call DrawSquare(-16, 16, 16, -16, 4)
End Sub
Private Sub DrawSquare(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single, Depth As Integer)
Picture1.Line (X1, Y1)-(X2, Y1), vbRed
Picture1.Line -(X2, Y2), vbRed
Picture1.Line -(X1, Y2), vbRed
Picture1.Line -(X1, Y1), vbRed
Dim U1 As Single
Dim V1 As Single
Dim P1 As Single
Dim Q1 As Single
U1 = Abs(X2 - X1) / (2 * (5 - Depth))
V1 = Abs(Y2 - Y1) / (2 * (5 - Depth))
P1 = X1 + (X2 - X1) / 2
Q1 = Y1 + (Y2 - Y1) / 2
If Depth > 1 Then '进行递归绘制
Call DrawSquare(P1 - U1 / 2, Y1 + 2 * V1, P1 + U1 / 2, Y1 + V1, Depth - 1)
Call DrawSquare(X2 + U1, Q1 + V1 / 2, X2 + 2 * U1, Q1 - V1 / 2, Depth - 1)
Call DrawSquare(P1 - U1 / 2, Y2 - V1, P1 + U1 / 2, Y2 - 2 * V1, Depth - 1)
Call DrawSquare(X1 - 2 * U1, Q1 + V1 / 2, X1 - U1, Q1 - V1 / 2, Depth - 1)
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -