VB可以使用子類化處理鼠標滾輪消息。
創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè),為客戶提供做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計開發(fā)服務(wù),多年建網(wǎng)站服務(wù)經(jīng)驗,各類網(wǎng)站都可以開發(fā),品牌網(wǎng)站制作,公司官網(wǎng),公司展示網(wǎng)站,網(wǎng)站設(shè)計,建網(wǎng)站費用,建網(wǎng)站多少錢,價格優(yōu)惠,收費合理。
新建工程
在窗體中添加滾動條VScroll1
'窗體代碼
Private Sub Form_Load()
'取得控件的句柄
hwndVS = VScroll1.hwnd
'保存smMap控件的默認窗口消息處理函數(shù)地址
OldWindowProc = GetWindowLong(VScroll1.hwnd, GWL_WNDPROC)
'將smMap控件的消息處理函數(shù)指定為自定義函數(shù)NewWindowProc
Call SetWindowLong(VScroll1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
添加一模塊:
Option Explicit
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 Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_MOUSEWHEEL = H20A
Public OldWindowProc As Long '用來保存系統(tǒng)默認的窗口消息處理函數(shù)的地址
Public hwndVS As Long '用來保存控件的句柄
'自定義的消息處理函數(shù)
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
If msg = WM_MOUSEWHEEL Then
'則對鼠標滾輪事件進行處理
If wParam = -7864320 Then '向下滾動
Form1.VScroll1.Value = Form1.VScroll1.Value + 1
ElseIf wParam = 7864320 Then '向上滾動
Form1.VScroll1.Value = Form1.VScroll1.Value - 1
End If
Else
'調(diào)用默認窗口消息處理函數(shù)
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, msg, wParam, lParam)
End If
End Function
將RTF的Padding設(shè)置比較大,例如10,此時我發(fā)現(xiàn)鼠標移動到RTF的邊緣部分的時候(不超過Padding的范圍),滾動條就能夠顯示,一旦鼠標移動到Content里面的時候,滾動條就不顯示
1、滾動條分為水平滾動條(HSCROLLBAR)和垂直滾動條(VSCROLLBAR)兩種,可以作為輸入設(shè)備或者速度、數(shù)量的指示器來使用.
2、基本屬性:object.max[=value],object.min[=value],最大最小范圍 object.value[=value],
點擊panel時得到panel的焦點,就可以用鼠標滾輪來控制滾動條了!代碼如下:
Private?Sub?Panel1_Click(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Panel1.Click
Panel1.Focus()
End?Sub
根據(jù)我的經(jīng)驗,應(yīng)該是PICtureBox沒有獲取焦點,而win10下不知道什么原因能自動獲取焦點,所以湊巧成功了,因此你應(yīng)該讓圖形框獲取焦點
如:picturebox1.focus()
不知道是不是解決了你的問題