关于改变窗体大小时,控件的大小随之改变的解决办法我在论坛中看到有许多种,有一种我觉得比较简便一点,但是我没有做成功,"dim MyCon as me.Controls "这句代码提示编译错误,缺少:New或类型名,下面我把源代码转载如下:请各位老师指点,到底错在哪里?或者还有什么更好的方法!
下面是具体的代码:
'下面两句话放在Form的"通用"中声明
dim FrmW as single '存放改变前的窗体的宽度
dim frmH as single '存放改变前的窗体的高度
Private Sub Form_Load()
if windowstate <>vbMinimized then
FrmW=me.Width
FrmH=me.Height
'上面两句是初始化模块变量
end if
End Sub
Private Sub Form_Resize()
if FrmW=0 or FrmH=0 then exit sub
dim MyCon as me.Controls
dim sig1 as single,sig2 as single
sig1 = Me.Width / FrmW
sig2 = Me.Height / FrmH
For Each MyCon In Me.Controls
If TypeOf MyCon Is Label Or _
TypeOf MyCon Is CommandButton Or _
TypeOf MyCon Is ListView Or _
TypeOf MyCon Is TextBox Then
With MyCon
.Left = Int(.Left * sig1)
.Top = Int(.Top * sig2)
.Width = Int(.Width * sig1)
.Height = Int(.Height * sig2)
End With
End If
Next MyCon
FrmW = Me.Width
FrmH = Me.Height
End Sub