永发信息网

vb 如何移动form1窗口

答案:3  悬赏:0  手机版
解决时间 2021-04-03 06:53
  • 提问者网友:泪痣哥哥
  • 2021-04-02 13:00
vb 如何移动form1窗口
最佳答案
  • 五星知识达人网友:天凉才是好个秋
  • 2021-04-02 14:21
向下移动10个单位:
Form1.Top = Form1.Top + 10
向上移动10个单位:
Form1.Top = Form1.Top - 10
向右移动10个单位:
Form1.Left = Form1.Left + 10
向左移动10个单位:
Form1.Left = Form1.Left - 10
全部回答
  • 1楼网友:雪起风沙痕
  • 2021-04-02 16:01
你的意思是移动一个没有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
'看看是否复合你的要求
  • 2楼网友:有你哪都是故乡
  • 2021-04-02 15:51
直接拖动鼠标移动就行了阿。。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯