Dim TT, TL, TW, TH  As Single
Dim RT, RL, RW, RH  As SinglePrivate Sub Form_Load()
TT = Text2.Top '保存Text2控件Top,Left,Width和Height属性
TL = Text2.Left
TW = Text2.Width
TH = Text2.HeightRT = RichTextBox1.Top '保存RichTextBox1控件Top,Left,Width和Height属性
TL = RichTextBox1.Left
RW = RichTextBox1.Width
RH = RichTextBox1.Height
'Form.Caption = CommonDialog1.FileName
End SubPrivate Sub Form_Resize()
Form1.ScaleHeight = 7065
Form1.ScaleWidth = 10230Text2.Top = TT  '设置Text2位置和大小
Text2.Left = TL
Text2.Width = TW
Text2.Height = THRichTextBox1.Top = RT 'RichTextBox1位置和大小
RichTextBox1.Left = RL
RichTextBox1.Width = RW
RichTextBox1.Height = RH
End Sub
这段代码能随窗体的自动化而变化,最小化时会出现错误

解决方案 »

  1.   

    在 form_resize 里增加一句:if windowstate=1 then exit sub   '如果是最小化,退出或加一句:
    on error resume next    '忽略错误
      

  2.   

    这样的比率太老套了,给你断参考的好了Dim a(), g(1) As Single
    Dim t As Integer, dt As Integer
    Private Sub Check1_Click()
        Form_Resize
    End Sub
    Private Sub Command1_Click()
        If t = 0 Then t = 0: dt = 100: Timer1.Enabled = True
    End SubPrivate 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
        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