左侧一个picture1作为容器,内有一个treeview1,要求窗体变化时这两个控件高度跟随向下变化,宽度不变。
右侧一个textbox1默认填满了窗体中除上面所述两个控件外的空隙,要求窗体变化时,textbox1向右扩展填满窗体右侧空隙。
左右侧相间的地方有一个Picture2,可以拖动使两侧窗体进行相应分割。这样的效果我做了很多回,可是总是不理想。
我用最简单的方法:先记录控件与窗体的比例,然后扩大时根据比例对控件的高度(或宽度)作相应调节,但发现有很多问题。
请高手赐教谢谢。

解决方案 »

  1.   

    补充一下:效果像windows的资源管理器界面。
      

  2.   

    打开VB,新建工程,选择 “VB 运用程序向导”,打开,下一步,选择“资源管理器样式”,点“完成”。运行看看效果如何。再看看代码,就什么都明白了。
      

  3.   

    就在Resize计算好了,绝对没问题啊
      

  4.   

    Option Explicit
    Dim MeWidth As Long
    Dim MeHeight As Long
    Private Type ctr
     Width As Long
     Height As Long
     Left As Long
     Top As Long
    End Type
    Dim myctr() As ctrPrivate Sub Form_Load()
    Dim i As Long
    MeWidth = Me.ScaleWidth
    MeHeight = Me.ScaleHeight
    ScaleHeight = 1000   ' 设置高度的单位值。
    ScaleWidth = 1000   ' 设置宽度的单位值。
    ReDim myctr(Controls.Count)
    '把每个控件的属性存入自定义类型数组
    For i = 0 To Controls.Count - 1
        myctr(i).Width = Controls(i).Width
        myctr(i).Height = Controls(i).Height
        myctr(i).Left = Controls(i).Left
        myctr(i).Top = Controls(i).Top
    Next
    End SubPrivate Sub Form_Resize()
    Dim i As Long
    Dim MyControl As Control
    ScaleHeight = 1000   ' 设置高度的单位值。
    ScaleWidth = 1000   ' 设置宽度的单位值。
    '把自定义类型数组存入每个控件的属性
    For i = 0 To Controls.Count - 1
       Controls(i).Width = myctr(i).Width
       Controls(i).Height = myctr(i).Height
       Controls(i).Left = myctr(i).Left
       Controls(i).Top = myctr(i).Top
    Next
    End Sub
      

  5.   


    Option ExplicitDim mbMoving As Boolean
    Const sglSplitLimit = 500Private Sub Form_Load()
       Picture1.Left = 0
       Picture1.Top = 0
       TreeView1.Left = 0
       TreeView1.Top = 0
       
       TreeView1.Nodes.Add , , "DeskTop", "DeskTop"
       
       TreeView1.Nodes.Add "DeskTop", tvwChild, , "Note1"
       
       TreeView1.Nodes(1).Expanded = True
       
    End SubPrivate Sub imgSplitter_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        With imgSplitter
            picSplitter.Move .Left, .Top, .Width \ 2, .Height - 20
        End With
        picSplitter.Visible = True
        mbMoving = True
    End Sub
    Private Sub imgSplitter_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim sglPos As Single
            If mbMoving Then
            sglPos = X + imgSplitter.Left
            If sglPos < sglSplitLimit Then
                picSplitter.Left = sglSplitLimit
            ElseIf sglPos > Me.Width - sglSplitLimit Then
                picSplitter.Left = Me.Width - sglSplitLimit
            Else
                picSplitter.Left = sglPos
            End If
        End If
    End Sub
    Private Sub imgSplitter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        SizeControls picSplitter.Left, Picture1, Text1
        picSplitter.Visible = False
        mbMoving = False
    End SubPrivate Sub Form_Resize()
        On Error Resume Next
        
        If Me.Width < 3000 Then Me.Width = 3000
        SizeControls imgSplitter.Left, Picture1, Text1
    End Sub
    Sub SizeControls(X As Single, ByVal objLeft As Object, ByVal objRight As Object)
        On Error Resume Next
            '设置 Width 属性
        If X < 1500 Then X = 1500
        If X > (Me.Width - 1500) Then X = Me.Width - 1500
        objLeft.Width = X
        imgSplitter.Left = X
        objRight.Left = X + 40
        objRight.Width = Me.Width - (objLeft.Width + 200)    '设置 Top 属性
      
       objLeft.Top = 0
        
       objRight.Top = objLeft.Top
            '设置 height 属性
        objLeft.Height = Me.ScaleHeight - 50
           objRight.Height = objLeft.Height
        imgSplitter.Top = objLeft.Top
        imgSplitter.Height = objLeft.Height
        
        
        TreeView1.Width = objLeft.Width
        TreeView1.Height = objLeft.Height
        
    End Sub'楼主要工程.加我QQ,我给你.
      

  6.   

    还是搞不定,好像上面的不太理想,现根据答案改问题如下。我的窗体只有五个控件:窗体上面留空为1500缇,用于放置功能选择按钮。
    左侧一个picture1,上面放入treeview1(用picture1的目的是在上边放置标题,下边放置分页按钮,中间treeview1列表。)
    右侧picture2的上面放入text1(用picture2的目的是取其边框)。
    要求最大化或调整时左侧控件只是调整picture1和treeview1高度,右侧控件调整picture2和text1高度和宽度。
    还有中间一个起调整分割的image1用于调整两侧控件比例。实现像资源管理器的效果。请高手再帮忙。
      

  7.   

    Private Sub Form_Resize()
        Dim i As Control
        If Me.WindowState = 1 Then Exit Sub '如果最小化则不进行改变
        On Error Resume Next
        For Each i In Me
            i.Top = (Me.ScaleHeight / LastH) * i.Top
            i.Height = (Me.ScaleHeight / LastH) * i.Height '这里注意了...对list必须单独设置...否则会发生恐怖的后果...
            i.Left = (Me.ScaleWidth / LastW) * i.Left
            i.Width = (Me.ScaleWidth / LastW) * i.Width
        Next
        LastW = Me.ScaleWidth
        LastH = Me.ScaleHeight
    End Sub
      

  8.   

    Sub SizeControls(X As Single, ByVal objLeft As Object, ByVal objRight As Object)
    注意此方法:一个窗体主要有二个部分,一个是左边,一个是右边.关于其它的控件.如果是在左边的请放在左边的容器里面.
    如果是在右边的请放在右边的容器里面.调用方法:sizeControls 左右容器的分界坐标,左边的容器,右边的容器 
    对于.是在左边容器里面的控件.如果想让控件与容器的宽度一致.在此方法里面设置.控件.Width=左边容器.Width-控件.Left-(边界常量,可以是100,也可以是200,自己设定)如果要高度一致,就这样设置
    控件.height=左边容器.Height-控件.Top-(边界常量,可以是100,也可以是200,自己设定)
    如果是在右边容器里面的,也采用相同的设置方式.如果左边的容器改为右边的容器
      

  9.   

    你要用DELPHI还用问吗... 直接就搞俩PANEL然后放东西进去.直接就设置CLIENT... 
      

  10.   

    问题是你的所有控件和窗体的ScaleMode设置得不一样.
    一样的话,按比例放大是没有问题的.
    但窗体上的控件调整大小不是简单的按比例放大
      

  11.   

    添加picture1,picture2,treeview1,text1控件
    Private Sub Form_Resize()
        On Error Resume Next
        Picture1.Left = 0
        Picture1.Top = 0
        Picture1.Width = Picture2.Left
        Picture1.Height = Me.ScaleHeight
        TreeView1.Left = 0
        TreeView1.Top = 0
        TreeView1.Width = Picture1.Width
        TreeView1.Height = Picture1.Height
        Text1.Left = Picture2.Left + Picture2.Width
        Text1.Top = 0
        Text1.Height = Me.ScaleHeight
        Text1.Width = Me.ScaleWidth - Text1.Left
        Picture2.Height = Me.ScaleHeight
        Picture2.Top = 0
        
    End Sub
    Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
         Call uObjectMoveLeft(Me, Picture2, "MouseDOWN", X, Y)
    End SubPrivate Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
         Call uObjectMoveLeft(Me, Picture2, "MouseMove", X, Y)
    End SubPrivate Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
         Call uObjectMoveLeft(Me, Picture2, "MouseUP", X, Y)
         Call Form_Resize
    End Sub添加模块窗体
    Public Mouse_Left_Down As Boolean
    Function uObjectMoveLeft(frm As Form, Pic As Object, State As String, X As Single, Y As Single)
       
       Select Case UCase(State)
              Case "MOUSEDOWN"
                   Mouse_Left_Down = True
                   Mouse_Down_X = X
                   Mouse_Down_Y = Y
                   Pic.ZOrder
              Case "MOUSEMOVE"
                   If Mouse_Left_Down = True Then
                      Pic.Left = Pic.Left + (X - Mouse_Down_X)
                   End If
              Case "MOUSEUP"
                   Mouse_Left_Down = False
                   If Pic.Top + Pic.Height > frm.ScaleHeight Then _
                      Pic.Top = frm.ScaleHeight - Pic.Height
                   If Pic.Left + Pic.Width > frm.ScaleWidth Then _
                      Pic.Left = frm.ScaleWidth - Pic.Width
                   If Pic.Top < 0 Then Pic.Top = 0
                   If Pic.Left < 0 Then Pic.Left = 0
       End Select
    End Function