我采用如下方法 在form上拖动1个控件
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const SC_MOVE = &HF010&
Private Const WM_SYSCOMMAND = &H112
Private Const HTCAPTION = 2
ReleaseCapture
Call SendMessage(Command1.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)请问一下 我现在要实现的是拖动控件1 让控件2跟随移动 有办法吗?
谢谢高人!!!
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const SC_MOVE = &HF010&
Private Const WM_SYSCOMMAND = &H112
Private Const HTCAPTION = 2
ReleaseCapture
Call SendMessage(Command1.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)请问一下 我现在要实现的是拖动控件1 让控件2跟随移动 有办法吗?
谢谢高人!!!
天狼工作室 http://www.j2soft.cn/
Option ExplicitPrivate bMoveing As BooleanPrivate Sub Init_Ctrl()
With tvw
.Nodes.Add , tvwFirst, "first", "第一节点"
End With
With lvw
.GridLines = True
.View = lvwReport
.ColumnHeaders.Add 1, "first", "第一列", .Width / 4
.ColumnHeaders.Add 2, "second", "第二列", .Width / 4
.ColumnHeaders.Add 3, "third", "第三列", .Width / 4
.ColumnHeaders.Add 4, "forth", "第四列", .Width / 4
End With
With pbxV
.Visible = False
End With
End SubPrivate Sub Form_Load()
Call Init_Ctrl
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
With Screen
.MousePointer = 0
End With
End SubPrivate Sub Form_Resize()
With Me
If .ScaleHeight = 0 Or .ScaleWidth = 0 Then Exit Sub
End With
With tvw
.Top = 60
.Left = 60
.Height = Me.ScaleHeight - 120
End With
With imgSpliter
.Left = tvw.Left + tvw.Width
.Top = tvw.Top
.Width = 60
.Height = tvw.Height
End With
With lvw
.Left = tvw.Left + tvw.Width + 60
.Top = tvw.Top
.Height = tvw.Height
End With
With pbxV
.Top = tvw.Top
.Height = tvw.Height
.Left = imgSpliter.Left + imgSpliter.Width
End With
End SubPrivate Sub imgSpliter_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
With imgSpliter
pbxV.Move .Left, .Top, .Width - 20, .Height - 20
End With
pbxV.Visible = True
bMoveing = True
End SubPrivate Sub imgSpliter_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Screen.MousePointer = 9
With imgSpliter
pbxV.Move .Left + .Width + x, .Top, .Width - 20, .Height - 20
End With
End SubPrivate Sub imgSpliter_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
With pbxV
.Visible = False
End With
Call Size_Ctrl
End SubPrivate Sub lvw_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Screen.MousePointer = 0
End SubPrivate Sub tvw_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Screen.MousePointer = 0
End SubPrivate Sub Size_Ctrl()
With tvw
.Width = pbxV.Left - .Left
End With
With imgSpliter
.Left = tvw.Left + tvw.Width
End With
With lvw
.Left = pbxV.Left + pbxV.Width
End With
End Sub'窗体中放置一个TreeView名为tvw,一个ListView名为lvw,一个PictureBox名为pbxV,一个Image名为imgSpliter这段代码,未经严格测试,只是本人闲暇时间写的,楼主可以大概看下.另外VB IDE本身是有示例的.
Dim cX As Long
Dim cY As LongPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - cX, Y - cY
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Drag 1
cX = X: cY = Y
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Drag 2
End Sub