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
我给你一串较实用的代码来于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
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
并取得mouse位置
就可以做到了。
有更简单的吗?
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