vb 移动picture1
代码如下:DimMxAsLong,MyAsLong,MyTopAsLong,MyLeftAsLongPrivateSubPicture1_MouseDown(Button...
代码如下:
Dim Mx As Long, My As Long, MyTop As Long, MyLeft As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mx = X
My = Y
MyTop = Picture1.Top
MyLeft = Picture1.Left
End Sub
Private Sub Picture1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = vbLeftButton Then Exit Sub
With Picture1
Picture1.Top = MyTop + Y - My
Picture1.Left = MyLeft + X - Mx
End With
End Sub
代码能达到目的,按下鼠标左键移动控件,但是效果非常差,闪烁,重影,
请高手指点,该怎么解决 展开
Dim Mx As Long, My As Long, MyTop As Long, MyLeft As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mx = X
My = Y
MyTop = Picture1.Top
MyLeft = Picture1.Left
End Sub
Private Sub Picture1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = vbLeftButton Then Exit Sub
With Picture1
Picture1.Top = MyTop + Y - My
Picture1.Left = MyLeft + X - Mx
End With
End Sub
代码能达到目的,按下鼠标左键移动控件,但是效果非常差,闪烁,重影,
请高手指点,该怎么解决 展开
2个回答
展开全部
控件的拖动可以用api解决,和借助其他控件解决(其他方法千变万化)下面给出2种拖动窗体的方法(窗体和picture都是一种窗体,只是父亲不同相信你能理解吧)
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
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 Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Me.Move Me.Left + X, Me.Top + Y
End Sub
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
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 Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Me.Move Me.Left + X, Me.Top + Y
End Sub
展开全部
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_mouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_mouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询