在FORM窗体中的各种控件怎样才能随着窗体的变而呢?

解决方案 »

  1.   

    在form_resize事件里设置控件大小
      

  2.   

    一般是在resize事件里写下控件跟窗体的比例

    picture.height=from.height/2
    picture.width=from.width/2
    picture.top=from.height/5
    picture.left=from.width/5
      

  3.   

    在form_resize事件中加入控件大小按比例改变的句子。
      

  4.   

    Form改变大小时同时改变其内Control之大小这个程式只是个范例,但在某些物件上不能使用,例如:Line,因为它没有Top, Left
    Width, Height所以在本程式中没有作用,不过呢,像这一类的东西可自己用另外程式
    去控制。
    Option Explicit
    Private InitWidth As Long       ' Form 的原始大小
    Private InitHeight As LongPrivate Sub Form_Load()
    InitWidth = ScaleWidth
    InitHeight = ScaleHeight
    Dim Ctl As Control
    ' 记录每个 Control 的原始位置、大小、字型大小, 放在 Tag 属性中
    On Error Resume Next '确保left, top, width, height, Tag属性没有全有的Control
    For Each Ctl In Me   '也能正常执行
        Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & Ctl.Width & " " & Ctl.Height & " "
        Ctl.Tag = Ctl.Tag & Ctl.FontSize & " "
    Next Ctl
    On Error GoTo 0
    End SubPrivate Sub Form_Resize()
    Dim D(4) As Double
    Dim I As Long
    Dim TempPos As Long
    Dim StartPos As Long
    Dim Ctl As Control
    Dim TempVisible As Boolean
    Dim ScaleX As Double
    Dim ScaleY As DoubleScaleX = ScaleWidth / InitWidth
    ScaleY = ScaleHeight / InitHeight
    On Error Resume Next
    For Each Ctl In Me
        TempVisible = Ctl.Visible
        Ctl.Visible = False
        StartPos = 1
        ' 读取 Control 的原始位置、大小、字型大小
        For I = 0 To 4
            TempPos = InStr(StartPos, Ctl.Tag, " ", vbTextCompare)
            If TempPos > 0 Then
                D(I) = Mid(Ctl.Tag, StartPos, TempPos - StartPos)
                StartPos = TempPos + 1
            Else
                D(I) = 0
            End If
            ' 根据比例设定 Control 的位置、大小、字型大小
            Ctl.Move D(0) * ScaleX, D(1) * ScaleY, D(2) * ScaleX, D(3) * ScaleY
            'Ctl.Width = D(2) * ScaleX
            'Ctl.Height = D(3) * ScaleY
            If ScaleX < ScaleY Then
                Ctl.FontSize = D(4) * ScaleX
            Else
                Ctl.FontSize = D(4) * ScaleY
            End If
        Next I
        Ctl.Visible = TempVisible
    Next Ctl
    On Error GoTo 0
    End SubPrivate Sub Form_Resize()
    FormResize Me
    End Sub
      

  5.   

    或者Private Sub Form_Resize()
    FormResize Me
    End Sub
    '''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''Option Explicit
    Public Xtwips As Integer, Ytwips As Integer
    Public Xpixels As Integer, Ypixels As IntegerType FRMSIZE
       Height As Long
       Width As Long
    End TypePublic RePosForm As Boolean
    Public DoResize As Boolean
    Dim MyForm As FRMSIZE
    Dim DesignX As Integer
    Dim DesignY As Integer
    Dim ScaleFactorX As Single, ScaleFactorY As Single 
    Sub Resize_For_Resolution(ByVal SFX As Single, ByVal SFY As Single, MyForm As Form)
    Dim I As Integer
    Dim SFFont As Single
    SFFont = (SFX + SFY) / 2
    On Error Resume Next
    With MyForm
      For I = 0 To .Count - 1
       If TypeOf .Controls(I) Is ComboBox Then
         .Controls(I).Left = .Controls(I).Left * SFX
         .Controls(I).Top = .Controls(I).Top * SFY
         .Controls(I).Width = .Controls(I).Width * SFX
       Else
         .Controls(I).Move .Controls(I).Left * SFX, _
          .Controls(I).Top * SFY, _
          .Controls(I).Width * SFX, _
          .Controls(I).Height * SFY
       End If
         .Controls(I).FontSize = .Controls(I).FontSize * SFFont
      Next I
      If RePosForm Then
         .Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
      End If
    End With
    End Sub
    Public Sub FormResize(TheForm As Form)
    On Error Resume Next
    Dim ScaleFactorX As Single, ScaleFactorY As Single
    If Not DoResize Then
       DoResize = True
       Exit Sub
    End If
    RePosForm = False
    ScaleFactorX = TheForm.Width / MyForm.Width
    ScaleFactorY = TheForm.Height / MyForm.Height
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
    MyForm.Height = TheForm.Height
    MyForm.Width = TheForm.Width
    End SubPublic Sub AdjustForm(TheForm As Form)
    Dim Res As String ' Returns resolution of system
    ' Put the design time resolution in here
    DesignX = 640
    DesignY = 480
    RePosForm = True
    DoResize = False
    Xtwips = Screen.TwipsPerPixelX
    Ytwips = Screen.TwipsPerPixelY
    Ypixels = Screen.Height / Ytwips
    Xpixels = Screen.Width / Xtwips
    ScaleFactorX = (Xpixels / DesignX)
    ScaleFactorY = (Ypixels / DesignY)
    TheForm.ScaleMode = 1
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
    Res = Str$(Xpixels) + "  by " + Str$(Ypixels)
    Debug.Print Res
    MyForm.Height = TheForm.Height
    MyForm.Width = TheForm.Width
     
    End Sub
      

  6.   

    Private Sub UserControl_Resize()
        
        '移动调整屏幕控件位置
        On Error Resume Next
        
        If UserControl.Parent.Height < Screen.Height / 2 Then
            UserControl.Parent.Height = Screen.Height / 2
            Exit Sub
        End If
        If UserControl.Parent.Width < Screen.Width / 2 Then
            UserControl.Parent.Width = Screen.Width / 2
            Exit Sub
        End If
        picMain.Move (Screen.Width - picMain.Width) / 2
        picPage.Move 80, picMain.Top + picMain.Height + 100, Abs(UserControl.ScaleWidth - 100), Abs(UserControl.ScaleHeight - (picMain.Top + picMain.Height + picFooter.Height + 100))
        picFooter.Move 80, picPage.Top + picPage.ScaleHeight + 100, picPage.WidthEnd Sub