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

代码能达到目的,按下鼠标左键移动控件,但是效果非常差,闪烁,重影,
请高手指点,该怎么解决
展开
 我来答
meiren777
2009-07-06 · 超过81用户采纳过TA的回答
知道小有建树答主
回答量:448
采纳率:0%
帮助的人:305万
展开全部
控件的拖动可以用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
farfamed
2009-07-07 · TA获得超过1039个赞
知道小有建树答主
回答量:520
采纳率:0%
帮助的人:1008万
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式