vb 如何移动form1窗口
3个回答
展开全部
你的意思是移动一个没有controlbox的form吧,给你一段代码,可以点住form任意位置移动,不限于点住标题栏,而且还可以扩展到别的控件上,如picturebox等
'新建一个vb工程,然后再放一个picturebox,把下面代码输入就可以,这样,你拖动picturebox可以移动,拖动窗体也可以移动.
Option Explicit
Dim bMove As Boolean
Dim oldX As Integer
Dim oldY As Integer
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Form1.Left = X - oldX + Form1.Left
Form1.Top = Y - oldY + Form1.Top
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Picture1.Left = X - oldX + Picture1.Left
Picture1.Top = Y - oldY + Picture1.Top
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = False
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End Sub
'看看是否复合你的要求
'新建一个vb工程,然后再放一个picturebox,把下面代码输入就可以,这样,你拖动picturebox可以移动,拖动窗体也可以移动.
Option Explicit
Dim bMove As Boolean
Dim oldX As Integer
Dim oldY As Integer
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Form1.Left = X - oldX + Form1.Left
Form1.Top = Y - oldY + Form1.Top
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Picture1.Left = X - oldX + Picture1.Left
Picture1.Top = Y - oldY + Picture1.Top
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = False
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End Sub
'看看是否复合你的要求
展开全部
向下移动10个单位:
Form1.Top = Form1.Top + 10
向上移动10个单位:
Form1.Top = Form1.Top - 10
向右移动10个单位:
Form1.Left = Form1.Left + 10
向左移动10个单位:
Form1.Left = Form1.Left - 10
Form1.Top = Form1.Top + 10
向上移动10个单位:
Form1.Top = Form1.Top - 10
向右移动10个单位:
Form1.Left = Form1.Left + 10
向左移动10个单位:
Form1.Left = Form1.Left - 10
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接拖动鼠标移动就行了阿。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询