VB 拖动picture 里的图片
我想用VB实现,单击鼠标左键或右键,移动鼠标,PICTURE框里的图片会随着鼠标移动而移动,但PICTUREBOX不会动,希望有人提供代码我的意思是,鼠标拖动就像同实现水...
我想用VB实现,单击鼠标左键或右键,移动鼠标,PICTURE框里的图片会随着鼠标移动而移动,但PICTUREBOX不会动,希望有人提供代码
我的意思是,鼠标拖动就像同实现水平,垂直滚动栏拖动的效果,而不是单单的把图片移动。就像AUTO CAD中,你按了右键,可以拖动你的视觉,但那幅图的坐标与位置是不变的!
二楼的程序好像差一点,运行时,总说PICTURE2.PICTURE 为0,我之前已经在FORMLOAD那里写了PICTURE2.PICTURE=PICTRE1.PICTURE 展开
我的意思是,鼠标拖动就像同实现水平,垂直滚动栏拖动的效果,而不是单单的把图片移动。就像AUTO CAD中,你按了右键,可以拖动你的视觉,但那幅图的坐标与位置是不变的!
二楼的程序好像差一点,运行时,总说PICTURE2.PICTURE 为0,我之前已经在FORMLOAD那里写了PICTURE2.PICTURE=PICTRE1.PICTURE 展开
展开全部
在窗体上添加picture1,并设置好图片属性Picture,然后在Picture1中(作为容器),添加一个Picture2控件,再添加如下代码,并运行
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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub MoveWindow(ByVal hwnd As Long)
Dim ret As Long
ReleaseCapture
ret = SendMessage(Picture2.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End Sub
Private Sub Form_Load()
Picture2.Move 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Picture2.Picture = Picture1.Picture
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
Picture1.Picture = LoadPicture("")
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub
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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub MoveWindow(ByVal hwnd As Long)
Dim ret As Long
ReleaseCapture
ret = SendMessage(Picture2.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End Sub
Private Sub Form_Load()
Picture2.Move 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Picture2.Picture = Picture1.Picture
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
Picture1.Picture = LoadPicture("")
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
展开全部
建立picture1\picture2控件。其中picture1放图片。左键点击允许移动,右键点击取消移动:
Private X1 As Single, Y1 As Single, blnS As Boolean
Private Sub Form_Load()
Picture2.Picture = Picture1.Picture
Picture2.Visible = False
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1
If blnS = False Then
X1 = X1 + X
Y1 = Y1 + Y
blnS = True
End If
Case 2
If blnS Then
X1 = X1 - X
Y1 = Y1 - Y
blnS = False
End If
End Select
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnS Then
Set Picture1.Picture = Nothing
Picture1.PaintPicture Picture2.Picture, X - X1, Y - Y1, Picture1.ScaleWidth, Picture1.ScaleHeight, 1, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End If
End Sub
PICTURE2.PICTURE 为0是因为PICTURE1没装载图片。在程序未运行时装载,或用Picture1.Picture = LoadPicture("c:\1.jpg")'其中c:\1.jpg是图片地址。
Private X1 As Single, Y1 As Single, blnS As Boolean
Private Sub Form_Load()
Picture2.Picture = Picture1.Picture
Picture2.Visible = False
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1
If blnS = False Then
X1 = X1 + X
Y1 = Y1 + Y
blnS = True
End If
Case 2
If blnS Then
X1 = X1 - X
Y1 = Y1 - Y
blnS = False
End If
End Select
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnS Then
Set Picture1.Picture = Nothing
Picture1.PaintPicture Picture2.Picture, X - X1, Y - Y1, Picture1.ScaleWidth, Picture1.ScaleHeight, 1, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End If
End Sub
PICTURE2.PICTURE 为0是因为PICTURE1没装载图片。在程序未运行时装载,或用Picture1.Picture = LoadPicture("c:\1.jpg")'其中c:\1.jpg是图片地址。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
添加两个picture控件,picture1和picture2
代码:
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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub MoveWindow(ByVal hwnd As Long)
Dim ret As Long
ReleaseCapture
ret = SendMessage(Picture2.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End Sub
Private Sub Form_Load()
With Picture2
.Left = Picture1.Left
.Top = Picture1.Top
.Height = Picture1.Height
.Width = Picture1.Width
End With
Picture2.Picture = Picture1.Picture
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
Picture1.Picture = LoadPicture("")
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub
'最后加一句,好像你这样做没什么意思
代码:
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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub MoveWindow(ByVal hwnd As Long)
Dim ret As Long
ReleaseCapture
ret = SendMessage(Picture2.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End Sub
Private Sub Form_Load()
With Picture2
.Left = Picture1.Left
.Top = Picture1.Top
.Height = Picture1.Height
.Width = Picture1.Width
End With
Picture2.Picture = Picture1.Picture
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
Picture1.Picture = LoadPicture("")
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub
'最后加一句,好像你这样做没什么意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询