我用treeview和listview控件实现的查询(treeview放在左边,listview放在右边,有点像本论坛的初始界面),但不知道怎么实现用鼠标调节这两个控件的宽度.各位大虾能为某人解决一下吗,我原先的设想是用mousedown,mousemove及来控制这两个控件的width属性。但是没有成功。

解决方案 »

  1.   

    利用一个控件的mousedown事件和mouseup事件可以实现用鼠标来控制一个控件的宽度,但是不能够实现通过用鼠标在两个控件(如treeview 和listview)的之间的边缘线上拖动来改变两个控件的宽度。因为mousedown的x参数永远不会等于控件的width的值。
      

  2.   

    dim bMove as boolean
    dim sX as singleprivate sub text1_movedown(... x as single ...)
    if text1.width-x<100 then
    bmove=true
    sX=X
    end if
    end subprivate sub text1_moveup(... x as single ...)
      if bmove=true then  text1.width=x+text1.width-sx
      bmove=false
    end sub
      

  3.   

    捕获Mousedown\mouseup\....
    并取得mouse位置
    就可以做到了。
    有更简单的吗?
      

  4.   

    我给你一串较实用的代码来于alen99
    Sub SizeControls(x As Single)
        On Error Resume Next
        '设置 Width 属性
        If x < 1500 Then x = 1500
        If x > (Me.Width - 1500) Then x = Me.Width - 1500
        tv1.Width = x
        imgSplitter.Left = x
        lv2.Left = x + 40
        lv2.Width = Me.Width - (tv1.Width + 140)
        '设置 Top 属性
        If Toolbar1.Visible Then
            tv1.Top = Toolbar1.Height + picTitles.Height
        Else
            tv1.Top = picTitles.Height
        End If    lv2.Top = tv2.Top
        '设置 height 属性
        tv1.Height = SSTab1.Height
        imgSplitter.Top = tv1.Top
        imgSplitter.Height = tv1.Height
    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 SubPrivate 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 SubPrivate Sub imgSplitter_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        SizeControls picSplitter.Left
        picSplitter.Visible = False
        mbMoving = False
    End Sub