VB.NET picturebox 内绘图完图形放大缩小移动 鼠标控制 。比较笨看了VB的代码不明白 求解
这是VB代码网上看到的窗体代码:OptionExplicitPrivateDeclareFunctionGetWindowLongLib"user32"Alias"Get...
这是VB代码 网上看到的
窗体代码:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private oldX As Long, oldY As Long
Private Sub Form_Load()
'窗口消息
prevWndProc = GetWindowLong(Picture1.hwnd, GWL_WNDPROC)
Call SetWindowLong(Picture1.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_Resize()
Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Private Sub Form_Unload(Cancel As Integer)
' 恢复窗口程序
Call SetWindowLong(Picture1.hwnd, GWL_WNDPROC, prevWndProc)
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldX = X
oldY = Y
End Sub
'可以用鼠标拖动图片
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.MousePointer = 5
If Button = 1 Then
Image1.Left = Image1.Left + X - oldX
Image1.Top = Image1.Top + Y - oldY
End If
End Sub
模块代码:
Option Explicit
'此模块用来实现PictureBox支持鼠标滚轮
Private Const WM_MOUSEWHEEL = &H20A
Public prevWndProc As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_MOUSEWHEEL Then
If wParam = -7864320 Then '向下滚动
Form1.Image1.Width = Form1.Image1.Width * 1.1
Form1.Image1.Height = Form1.Image1.Height * 1.1
ElseIf wParam = 7864320 Then '向上滚动
Form1.Image1.Width = Form1.Image1.Width * 0.9
Form1.Image1.Height = Form1.Image1.Height * 0.9
End If
Else
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End If
End Function 展开
窗体代码:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private oldX As Long, oldY As Long
Private Sub Form_Load()
'窗口消息
prevWndProc = GetWindowLong(Picture1.hwnd, GWL_WNDPROC)
Call SetWindowLong(Picture1.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_Resize()
Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Private Sub Form_Unload(Cancel As Integer)
' 恢复窗口程序
Call SetWindowLong(Picture1.hwnd, GWL_WNDPROC, prevWndProc)
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldX = X
oldY = Y
End Sub
'可以用鼠标拖动图片
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.MousePointer = 5
If Button = 1 Then
Image1.Left = Image1.Left + X - oldX
Image1.Top = Image1.Top + Y - oldY
End If
End Sub
模块代码:
Option Explicit
'此模块用来实现PictureBox支持鼠标滚轮
Private Const WM_MOUSEWHEEL = &H20A
Public prevWndProc As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_MOUSEWHEEL Then
If wParam = -7864320 Then '向下滚动
Form1.Image1.Width = Form1.Image1.Width * 1.1
Form1.Image1.Height = Form1.Image1.Height * 1.1
ElseIf wParam = 7864320 Then '向上滚动
Form1.Image1.Width = Form1.Image1.Width * 0.9
Form1.Image1.Height = Form1.Image1.Height * 0.9
End If
Else
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End If
End Function 展开
2个回答
展开全部
。net 不用api就行
缩放操作
Function 缩放(ByVal bitmap As Bitmap, ByVal 倍数 As Single) As Bitmap
Dim w As Integer = bitmap.Width * 倍数
Dim h As Integer = bitmap.Height * 倍数
Dim tem As New Bitmap(w, h)
Dim g As Graphics = Graphics.FromImage(tem)
g.DrawImage(bitmap, New Rectangle(0, 0, w, h), New Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel)
g.Dispose()
Return tem
End Function
鼠标滚轮事件 MouseWheel
MouseEventArgs.Delta 值可以判断滚动方向
缩放操作
Function 缩放(ByVal bitmap As Bitmap, ByVal 倍数 As Single) As Bitmap
Dim w As Integer = bitmap.Width * 倍数
Dim h As Integer = bitmap.Height * 倍数
Dim tem As New Bitmap(w, h)
Dim g As Graphics = Graphics.FromImage(tem)
g.DrawImage(bitmap, New Rectangle(0, 0, w, h), New Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel)
g.Dispose()
Return tem
End Function
鼠标滚轮事件 MouseWheel
MouseEventArgs.Delta 值可以判断滚动方向
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是VB6的代码,不是VB.NET的
追问
恩 网上只看到VB的代码 还不太懂 需要的是vb.net的 能否就这个VB转为VB.NET 或者就VB.NET实现这个功能给些建议 谢谢
追答
不是所有的VB6代码都能转到VB.NET,毕竟差异蛮大的,特别你这个代码,用了很多API函数,另外VB6不支持鼠标滚轮,但VB.NET是支持的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询