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
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
展开全部
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询