'----------------------------------------------------------------Dim a(), g(1) As Single Dim t As Integer, dt As IntegerPrivate Sub Form_Activate() If g(0) = 0 Then '原始值只記錄一次 g(0) = Form1.ScaleWidth: g(1) = Form1.ScaleHeight '一開始表單的大小 ReDim a(Form1.Controls.Count - 1, 5) j = 0 For Each i In Form1.Controls '記錄每個物件的資料 a(j, 0) = i.Name On Error Resume Next '避免某些物件沒有指定的屬性而錯誤 a(j, 1) = i.Left: a(j, 2) = i.Top a(j, 3) = i.Width: a(j, 4) = i.Height a(j, 5) = i.FontSize On Error GoTo 0 '取消錯誤處理 j = j + 1 Next i t = 0: dt = 100 End If End SubPrivate Sub Form_Resize() If Form1.WindowState <> 1 And g(0) > 0 And g(1) > 0 Then '重算物件的新位置 For i = 0 To Form1.Controls.Count - 1 Set b = Controls(a(i, 0)) On Error Resume Next b.Left = a(i, 1) / g(0) * Form1.ScaleWidth b.Top = a(i, 2) / g(1) * Form1.ScaleHeight b.Width = a(i, 3) / g(0) * Form1.ScaleWidth b.Height = a(i, 4) / g(1) * Form1.ScaleHeight If Form1.ScaleWidth / g(0) < Form1.ScaleHeight / g(1) Then b.FontSize = a(i, 5) / g(0) * Form1.ScaleWidth Else b.FontSize = a(i, 5) / g(1) * Form1.ScaleHeight End If On Error GoTo 0 If TypeOf b Is PictureBox Then 'If Check1.Value = 1 Then b.PaintPicture b.Picture, 0, 0, b.ScaleWidth, b.ScaleHeight Else b.Cls End If Set b = Nothing Next i End If End Sub偶喜歡用這個,但是別人說它太復雜,呵呵
试 了一下 编译错误: For Each控件变量必须为变体或对象
ei...不會啊,你上面有什麼東西 我給你mail程序過來,你自己看是不是對的留你的mail
已經發給你了,我隨便放了幾個控件上去,當然你可以再丟一點對了,我是sina 的信箱
dim bmaxsize=truePrivate Sub Form_Resize() Dim XW, XH, i, W1, H1 As Integer XW = 76 XH = 76 W1 = Screen.Width \ Screen.TwipsPerPixelX H1 = Screen.Height \ Screen.TwipsPerPixelY If W1 = 1024 And H1 = 768 Then XW = 58 XH = 61 Else If W1 = 1280 And H1 = 1024 Then XW = 46.5 XH = 44 End If End If
If WindowState = 2 And BmaxSize = False Then BmaxSize = True
Dim t As Integer, dt As IntegerPrivate Sub Form_Activate()
If g(0) = 0 Then '原始值只記錄一次
g(0) = Form1.ScaleWidth: g(1) = Form1.ScaleHeight '一開始表單的大小
ReDim a(Form1.Controls.Count - 1, 5)
j = 0
For Each i In Form1.Controls '記錄每個物件的資料
a(j, 0) = i.Name
On Error Resume Next '避免某些物件沒有指定的屬性而錯誤
a(j, 1) = i.Left: a(j, 2) = i.Top
a(j, 3) = i.Width: a(j, 4) = i.Height
a(j, 5) = i.FontSize
On Error GoTo 0 '取消錯誤處理
j = j + 1
Next i
t = 0: dt = 100
End If
End SubPrivate Sub Form_Resize()
If Form1.WindowState <> 1 And g(0) > 0 And g(1) > 0 Then
'重算物件的新位置
For i = 0 To Form1.Controls.Count - 1
Set b = Controls(a(i, 0))
On Error Resume Next
b.Left = a(i, 1) / g(0) * Form1.ScaleWidth
b.Top = a(i, 2) / g(1) * Form1.ScaleHeight
b.Width = a(i, 3) / g(0) * Form1.ScaleWidth
b.Height = a(i, 4) / g(1) * Form1.ScaleHeight
If Form1.ScaleWidth / g(0) < Form1.ScaleHeight / g(1) Then
b.FontSize = a(i, 5) / g(0) * Form1.ScaleWidth
Else
b.FontSize = a(i, 5) / g(1) * Form1.ScaleHeight
End If
On Error GoTo 0
If TypeOf b Is PictureBox Then
'If Check1.Value = 1 Then b.PaintPicture b.Picture, 0, 0, b.ScaleWidth, b.ScaleHeight Else b.Cls
End If
Set b = Nothing
Next i
End If
End Sub偶喜歡用這個,但是別人說它太復雜,呵呵
编译错误:
For Each控件变量必须为变体或对象
我給你mail程序過來,你自己看是不是對的留你的mail
Dim XW, XH, i, W1, H1 As Integer
XW = 76
XH = 76
W1 = Screen.Width \ Screen.TwipsPerPixelX
H1 = Screen.Height \ Screen.TwipsPerPixelY
If W1 = 1024 And H1 = 768 Then
XW = 58
XH = 61
Else
If W1 = 1280 And H1 = 1024 Then
XW = 46.5
XH = 44
End If
End If
If WindowState = 2 And BmaxSize = False Then
BmaxSize = True
Label1.Left = Label1.Left * 76 / XW
Label1.Top = Label1.Top * 76 / XH
Label1.Height = Label1.Height * 76 / XH
Label1.Width = Label1.Width * 76 / XW
Label10.Left = Label10.Left * 76 / XW
Label10.Top = Label10.Top * 76 / XH
Label10.Height = Label10.Height * 76 / XH
Label10.Width = Label10.Width * 76 / XW
Label11.Left = Label11.Left * 76 / XW
Label11.Top = Label11.Top * 76 / XH
Label11.Height = Label11.Height * 76 / XH
Label11.Width = Label11.Width * 76 / XW
Label12.Left = Label12.Left * 76 / XW
Label12.Top = Label12.Top * 76 / XH
Label12.Height = Label12.Height * 76 / XH
Label12.Width = Label12.Width * 76 / XW
Form1.Visible = True
Else
If WindowState = 0 And BmaxSize = True Then
BmaxSize = False
Label1.Left = Label1.Left * XW / 76
Label1.Top = Label1.Top * XH / 76
Label1.Height = Label1.Height * XH / 76
Label1.Width = Label1.Width * XW / 76
Label10.Left = Label10.Left * XW / 76
Label10.Top = Label10.Top * XH / 76
Label10.Height = Label10.Height * XH / 76
Label10.Width = Label10.Width * XW / 76
Label11.Left = Label11.Left * XW / 76
Label11.Top = Label11.Top * XH / 76
Label11.Height = Label11.Height * XH / 76
Label11.Width = Label11.Width * XW / 76
Label12.Left = Label12.Left * XW / 76
Label12.Top = Label12.Top * XH / 76
Label12.Height = Label12.Height * XH / 76
Label12.Width = Label12.Width * XW / 76
Form1.Visible = True
End If
End If
End Sub
me.height=Screen.Height \ Screen.TwipsPerPixelY