现在采用的方法
方法1
Private Sub Form_Load()
Set Label1.Container = Picture1
With Label1
.Left = 3000
.Top = 1900
.Caption = "现在位置定位精度"
.AutoSize = True
.BackStyle = 1
End With
End Sub方法2
Private Sub Form_Load() Set Label1.Container = Picture1
With Label1.Container
.Height = 400
.Width = 0.7
MsgBox .Width & "---" & .Height
End With
''
With Label1
.Left = 100
.Top = 150
.Caption = "现在是什么位置"
.AutoSize = True
.BackStyle = 1
.Alignment = 2
End With
End Sub上述方法存在问题是,没有找到准确定位的单位换算方法.
1 定位靠试算,label到底是以Form为准计算,还是与Picture的位置有关.
最好是以PictureBox为基准计算.
2 .Alignment = 2 对中试了n次都没成功,.Alignment 不是Label自己的对齐吧,是不是与其它Lable对齐.
一点小问题,就是达不到目标需求.
方法1
Private Sub Form_Load()
Set Label1.Container = Picture1
With Label1
.Left = 3000
.Top = 1900
.Caption = "现在位置定位精度"
.AutoSize = True
.BackStyle = 1
End With
End Sub方法2
Private Sub Form_Load() Set Label1.Container = Picture1
With Label1.Container
.Height = 400
.Width = 0.7
MsgBox .Width & "---" & .Height
End With
''
With Label1
.Left = 100
.Top = 150
.Caption = "现在是什么位置"
.AutoSize = True
.BackStyle = 1
.Alignment = 2
End With
End Sub上述方法存在问题是,没有找到准确定位的单位换算方法.
1 定位靠试算,label到底是以Form为准计算,还是与Picture的位置有关.
最好是以PictureBox为基准计算.
2 .Alignment = 2 对中试了n次都没成功,.Alignment 不是Label自己的对齐吧,是不是与其它Lable对齐.
一点小问题,就是达不到目标需求.
有这句,label的top和left就是以picture为准的2 With Label1.Container '没有必要,此处直接Label1
.Height = 400
.Width = 0.7 '宽度太小了吧,这样就看不到了,应设大点3 Alignment 好象在设计时有效
目标需求是,p(x,y)基准,label对中.
现在遇到的问题是,left与Alignment,没有实现label对中的目标需求.
Dim picName
picName = "C:\Documents and Settings\Administrator\桌面\压力容器制造\VB\WMF\"
picName = picName & "SO_MFM.wmf"
With Form1
.ScaleMode = 3
'.ScaleHeight = 1
'.ScaleWidth = 1
.Width = 8100
.Height = 7800
'Debug.Print .Width, .Height
End With
With Form1.Picture1
'Debug.Print .Width, .Height
.Picture = LoadPicture(picName) '这时加入背景图,使其一运行就充满窗体
End With
Dim ii
For ii = 0 To 1
Set txtLab(ii).Container = Form1.Picture1
With txtLab(ii)
.Left = 10 + ii * 50
.Top = 5 + ii * 10
.AutoSize = True
.BackStyle = 1
.Caption = ii
Debug.Print .Width, .Height
End With
Next ii
With txtLab(0).Container
.Height = 400
.Width = .Height * 0.62
'MsgBox .Width & "---" & .Height
End With
End Sub
.ScaleMode = 3
'.ScaleHeight = 1
'.ScaleWidth = 1
怎么试,form与Picturebox的位置有点问题.
Private Sub Form_Load()
With Form1
Debug.Print .Width, .Height
.ScaleMode = 3
xx = .Picture1.Width / 2
For ii = 0 To 2
With .txtLab(ii)
.Left = xx - .Width / 2
'.Alignment = 0
.AutoSize = True
Debug.Print xx
.Caption = "ccc" & ii
End With
Next ii
End With
End Sub