1个回答
展开全部
下面的代码
只需建立一个form不需要手动添加其他控件,将代码写在窗体中,运行看看是不是你要的效果
Const Pi As Double = 3.14159265358979
Private Type P
X As Long
Y As Long
End Type
Private Sub Form_Load()
Dim r As Long
Dim oControl(11) As Object '动态控件
Dim pCir As P
Dim cPT(11) As P
Dim i As Integer
If Me.Width < Me.Height Then r = Me.Width / 3 Else r = Me.Height / 3 '计算半径
pCir.X = Me.Width / 2: pCir.Y = Me.Height / 2 '计算圆心坐标
For i = 0 To 11 '计算控件坐标
cPT(i).X = pCir.X + Sin(Pi * i * 30 / 180) * r: cPT(i).Y = pCir.Y - Cos(Pi * i * 30 / 180) * r
Next i
For i = 0 To 11 '动态生成LBL控件,并设置坐标和属性
Set oControl(i) = Controls.Add("VB.Label", "lblClock" & CStr(i))
If i = 0 Then oControl(i).Caption = "12" Else oControl(i).Caption = i
oControl(i).Width = 180: oControl(i).Height = 180
oControl(i).Visible = True
oControl(i).Left = cPT(i).X: oControl(i).Top = cPT(i).Y
Next i
End Sub
写的不是很严格,比如所有LBL的Left和Top坐标应该减去lbl.width/2和lbl.height/2,常数应定义为大写,请你根据你的程序再修改吧。
只需建立一个form不需要手动添加其他控件,将代码写在窗体中,运行看看是不是你要的效果
Const Pi As Double = 3.14159265358979
Private Type P
X As Long
Y As Long
End Type
Private Sub Form_Load()
Dim r As Long
Dim oControl(11) As Object '动态控件
Dim pCir As P
Dim cPT(11) As P
Dim i As Integer
If Me.Width < Me.Height Then r = Me.Width / 3 Else r = Me.Height / 3 '计算半径
pCir.X = Me.Width / 2: pCir.Y = Me.Height / 2 '计算圆心坐标
For i = 0 To 11 '计算控件坐标
cPT(i).X = pCir.X + Sin(Pi * i * 30 / 180) * r: cPT(i).Y = pCir.Y - Cos(Pi * i * 30 / 180) * r
Next i
For i = 0 To 11 '动态生成LBL控件,并设置坐标和属性
Set oControl(i) = Controls.Add("VB.Label", "lblClock" & CStr(i))
If i = 0 Then oControl(i).Caption = "12" Else oControl(i).Caption = i
oControl(i).Width = 180: oControl(i).Height = 180
oControl(i).Visible = True
oControl(i).Left = cPT(i).X: oControl(i).Top = cPT(i).Y
Next i
End Sub
写的不是很严格,比如所有LBL的Left和Top坐标应该减去lbl.width/2和lbl.height/2,常数应定义为大写,请你根据你的程序再修改吧。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询