在vb中如何精确同步移动多个窗体?
我在搞玻璃窗体,但是要用两个窗体显示内容,如何调用windowsAPI实现多个窗体的同步移动?...
我在搞玻璃窗体,但是要用两个窗体显示内容,如何调用windows API实现多个窗体的同步移动?
展开
3个回答
展开全部
'将以下代码粘贴到Form1里
Private Type POINT
X As Single
Y As Single
End Type
Dim FormP As POINT '记录窗体相对位置
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form2.Left = FormP.X + Form1.Left '移动窗体Form2
Form2.Top = FormP.Y + Form1.Top
Form2.Show
End Sub
Private Sub Form_load()
Form2.Show
FormP.X = Form2.Left - Form1.Left
FormP.Y = Form2.Top - Form1.Top
End Sub
'以上代码简单但是有延迟
'--------------------------------------------------------------------------------------
'以下代码复杂但是无延迟
'Form1.BorderStyle = 0
Private Type POINT
X As Single
Y As Single
End Type
Dim FormP12 As POINT
Dim FormP As POINT
'记录窗体原始位置
Dim MouseP As POINT
'记录鼠标按下时的位置
Dim MouseLButtonDown As Boolean
'记录鼠标左键是否按下
Private Sub Command1_Click()
End '退出程序
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
FormP.X = Form1.Left
'记下窗体原始坐标位置
FormP.Y = Form1.Top
MouseP.X = X
'记下鼠标按下时的位置
MouseP.Y = Y
If Button = 1 Then
MouseLButtonDown = True
'鼠标左键按下
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MouseLButtonDown Then
Form1.Left = FormP.X + (X - MouseP.X) '移动窗体1
Form1.Top = FormP.Y + (Y - MouseP.Y)
Form2.Left = Form1.Left + FormP12.X '移动窗体2
Form2.Top = Form1.Top + FormP12.Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseLButtonDown = False
'鼠标左键弹起
End Sub
Private Sub Form_load()
Form2.Show
FormP12.X = Form2.Left - Form1.Left
FormP12.Y = Form2.Top - Form1.Top
End Sub
Private Type POINT
X As Single
Y As Single
End Type
Dim FormP As POINT '记录窗体相对位置
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form2.Left = FormP.X + Form1.Left '移动窗体Form2
Form2.Top = FormP.Y + Form1.Top
Form2.Show
End Sub
Private Sub Form_load()
Form2.Show
FormP.X = Form2.Left - Form1.Left
FormP.Y = Form2.Top - Form1.Top
End Sub
'以上代码简单但是有延迟
'--------------------------------------------------------------------------------------
'以下代码复杂但是无延迟
'Form1.BorderStyle = 0
Private Type POINT
X As Single
Y As Single
End Type
Dim FormP12 As POINT
Dim FormP As POINT
'记录窗体原始位置
Dim MouseP As POINT
'记录鼠标按下时的位置
Dim MouseLButtonDown As Boolean
'记录鼠标左键是否按下
Private Sub Command1_Click()
End '退出程序
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
FormP.X = Form1.Left
'记下窗体原始坐标位置
FormP.Y = Form1.Top
MouseP.X = X
'记下鼠标按下时的位置
MouseP.Y = Y
If Button = 1 Then
MouseLButtonDown = True
'鼠标左键按下
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MouseLButtonDown Then
Form1.Left = FormP.X + (X - MouseP.X) '移动窗体1
Form1.Top = FormP.Y + (Y - MouseP.Y)
Form2.Left = Form1.Left + FormP12.X '移动窗体2
Form2.Top = Form1.Top + FormP12.Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseLButtonDown = False
'鼠标左键弹起
End Sub
Private Sub Form_load()
Form2.Show
FormP12.X = Form2.Left - Form1.Left
FormP12.Y = Form2.Top - Form1.Top
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询