在Access表单中使用鼠标滚轮滚动到备忘录框或组合框

huangapple go评论65阅读模式
英文:

Using Mouse Wheel into the Memo Box or Combo Box in Access Forms

问题

我有一个名为“NewStaff”的Access表单,其中包含一个备忘录框。当我点击其中时,滚动鼠标滚轮会导致退出该字段,并且不会放置在备忘录框内的文本上。最后,我将以下代码放在表单的鼠标滚轮事件上,现在我可以通过滚动鼠标滚轮来移动备忘录框的行。

Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
    Dim i As Long
    Dim s As String
    If Me.ActiveControl.Name = "NewStaff" Then
        If Count > 0 Then
            For i = 1 To Count
                s = s & "{DOWN}"
            Next i
        Else
            For i = 1 To -Count
                s = s & "{UP}"
            Next i
        End If
        SendKeys s
    End If
End Sub

问题在于光标会跳跃三行到三行最终离开该字段

是否有一种逐行移动并保持在备忘录框内的方法?...谢谢

英文:

I have an Access form named "NewStaff" that contains a Memo box. When I clicked inside it, rolling the mouse wheel would cause an exit to this field and it would not be placed on the text inside the Memo box. Finally, I put the following code on the MouseWheel Event form and now I can move the Memo box lines by rolling the mouse wheel.

> Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
> Dim i As Long
> Dim s As String
> If Me.ActiveControl.Name = "ُNewStaff" Then
> If Count > 0 Then
> For i = 1 To Count
> s = s & "{DOWN}"
> Next i
> Else
> For i = 1 To -Count
> s = s & "{UP}"
> Next i
> End If
> SendKeys s
> End If
> End Sub

The problem is that the cursor has jumping three lines to three lines and finally leaves the field!

Is there a way to go line by line and stay in Memo box for the cursor? ... Thanks

答案1

得分: 2

使用SendKeys UP/DOWN来滚动文本不够灵活 - 用户不一定希望光标移动,只需要文本滚动。另外,你提到的“突然退出”效果。

很久以前,我找到并适应了这个解决方案。将所有代码粘贴到一个模块中,并按照注释中所示进行调用。

Option Compare Database
Option Explicit

Private Const WM_VSCROLL = &H115
Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1

Public 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 Declare Function apiGetFocus Lib "user32" _
        Alias "GetFocus" _
         () As Long
'

' 用鼠标滚轮滚动多行文本框。文本框必须具有焦点。
'
' 在包含多行文本框的表单的MouseWheel事件中调用此子例,如下所示:
'
' Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
'    Call MouseWheelScroll(Count)
' End Sub
'
' 来源
' http://www.access-programmers.co.uk/forums/showthread.php?t=195679
' http://www.extramiledata.com/scroll-microsoft-access-text-box-using-mouse-wheel/

Public Sub MouseWheelScroll(ByVal Count As Long)

    Dim LinesToScroll As Integer
    Dim hwndActiveControl As Long
    
    If Screen.ActiveControl.Properties.Item("ControlType") = acTextBox Then
        hwndActiveControl = fhWnd(Screen.ActiveControl)
        For LinesToScroll = 1 To Abs(Count)
            SendMessage hwndActiveControl, WM_VSCROLL, IIf(Count < 0, SB_LINEUP, SB_LINEDOWN), 0&
        Next
    End If

End Sub

' 来源: http://access.mvps.org/access/api/api0027.htm
' 代码由 Dev Ashish 提供

Private Function fhWnd(ctl As Control) As Long
    
    On Error Resume Next
    ' 我们只在Screen.ActiveControl中使用此函数,因此这不是必要的。
    ' 我记不清是否在某些情况下发现它有害。
    ' ctl.SetFocus
    
    fhWnd = apiGetFocus
    On Error GoTo 0
    
End Function

希望这能帮助你。

英文:

Using SendKeys UP/DOWN to scroll is clunky - users don't necessarily want the cursor to move, only the text to scroll. Plus the "sudden exit" effect you noticed.

A long time ago I found and adapted this solution.
Paste all the code into a module, and call it as shown in the comments.

Option Compare Database
Option Explicit

Private Const WM_VSCROLL = &amp;H115
Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1

Public Declare Function SendMessage Lib &quot;user32&quot; _
   Alias &quot;SendMessageA&quot; _
   (ByVal hWnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   LParam As Any) _
   As Long
   
Private Declare Function apiGetFocus Lib &quot;user32&quot; _
        Alias &quot;GetFocus&quot; _
         () As Long
&#39;

&#39; Scroll multi-line textboxes with the mouse wheel. The textbox must have the focus.
&#39;
&#39; Call this sub in the MouseWheel event of the form(s) containing multi-line textboxes, like this:
&#39;
&#39; Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
&#39;    Call MouseWheelScroll(Count)
&#39; End Sub
&#39;
&#39; Sources
&#39; http://www.access-programmers.co.uk/forums/showthread.php?t=195679
&#39; http://www.extramiledata.com/scroll-microsoft-access-text-box-using-mouse-wheel/

Public Sub MouseWheelScroll(ByVal Count As Long)

    Dim LinesToScroll As Integer
    Dim hwndActiveControl As Long
    
    If Screen.ActiveControl.Properties.Item(&quot;ControlType&quot;) = acTextBox Then
        hwndActiveControl = fhWnd(Screen.ActiveControl)
        For LinesToScroll = 1 To Abs(Count)
            SendMessage hwndActiveControl, WM_VSCROLL, IIf(Count &lt; 0, SB_LINEUP, SB_LINEDOWN), 0&amp;
        Next
    End If

End Sub

&#39; Source: http://access.mvps.org/access/api/api0027.htm
&#39; Code Courtesy of Dev Ashish

Private Function fhWnd(ctl As Control) As Long
    
    On Error Resume Next
    &#39; We only use this function for Screen.ActiveControl, so this is not necessary.
    &#39; I can&#39;t remember if I found it harmful in some situations.
    &#39; ctl.SetFocus
    
    fhWnd = apiGetFocus
    On Error GoTo 0
    
End Function

答案2

得分: 1

这是一个鼠标设置:

英文:

I believe that's a mouse setting:

在Access表单中使用鼠标滚轮滚动到备忘录框或组合框

答案3

得分: 0

好的,我找到了一个问题的解决方案。在鼠标设置(鼠标属性)中跳“三行到三行”的问题在Windows控制面板中,它默认为数字三。我们必须将其更改为数字一!

路径:控制面板 > 鼠标属性 > 滚轮

现在,我们只需修复突然退出备忘录框的问题!

英文:

Well, I found a solution to one of the problems. The problem of jumping "three lines to three lines" in the mouse settings (Mouse Properties) was in the Windows Control Panel, which by default is on the number three. We have to change it to number one!

Path: Control Panel > Mouse Properties > Wheel

在Access表单中使用鼠标滚轮滚动到备忘录框或组合框

Now, We just have to fix the sudden exit from the Memo box!

huangapple
  • 本文由 发表于 2023年5月7日 18:08:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定