如何测试光标是否在文本框中? [英] How to test if cursor is in text box?

查看:63
本文介绍了如何测试光标是否在文本框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,我*不希望用户能够使用

PageUp / PageDown键*除非*光标位于特定的文本框中。


我正在使用这段代码:


Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)

Select Case KeyCode

案例33,34

KeyCode = 0

结束选择

退出子


但是如何允许在特定文本中使用PageUp / PageDown键

框?有问题的文本框--txtNoteText - 将包含大量文本,

perhpas几页,从备忘录字段填充。


谢谢提前。


我也希望能够使用鼠标滚轮滚动文本

框,但我不确定这是否可行。我正在使用Stephen Lebans

MouseHook DLL,它关闭了窗体中的鼠标滚轮,但我无法获得

当光标在文本中时它会重新打开盒子


我尝试了以下代码,但它不起作用。我会决定使用

PageUp / PageDown Key,但是...


Private Sub txtNoteText_Enter()

Dim blRet As Boolean

blRet = MouseWheelON

End Sub


私有子txtNoteText_Exit(取消为整数)

Dim blRet As Boolean

blRet = MouseWheelOFF(False)

End Sub

解决方案

要查看当前活动的控件是什么,请尝试:

Screen.ActiveControl


务必使用错误处理。试图阅读它可能会出错。


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" deko" <无**** @ hotmail.com>在消息中写道

新闻:电视******************* @ newssvr25.news.prodigy。 com ...

我有一个表格,我*不希望用户能够使用
PageUp / PageDown键*除非*光标在特定的文本框中。

我正在使用这段代码:

Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
Select Case KeyCode
案例33 ,34
KeyCode = 0
结束选择
退出子

但是如何允许在特定的
文本框中使用PageUp / PageDown键?有问题的文本框--txtNoteText - 将包含大量文本,
遍布几页,从备注字段填充。

提前致谢。
MouseHook DLL,它会关闭窗体中的鼠标滚轮,但是当光标在文本框中时,我不能让它重新打开
我尝试了下面的代码,但它不起作用。我决定使用
PageUp / PageDown Key,但是......

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
结束Sub

Private Sub txtNoteText_Exit(取消为整数)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub



>要查看当前活动的控件是什么,请尝试:

Screen.ActiveControl




谢谢 - 这似乎有效。但现在的问题是,在当前

记录滚动到字段底部之后,表单会跳转到下一个
记录,这就是我的行为。我试图避免。这是代码:


Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)

On Error GoTo HandleErr

选择Case KeyCode

案例33,34

结束选择

[代码省略]

结束子


有没有办法阻止表单移动到下一条记录?


顺便说一下,这个表单的RecordSource是从克隆的记录集构建的:


Private Sub Form_Open(取消为整数)

错误GoTo HandleErr

Dim strNid As String

Dim lngNid As Long

Dim rst作为DAO.Recordset

Dim blRet As Boolean

blRet = MouseWheelOFF(False)

如果我.OpenArgs =" OldNote"然后

lngNid = Forms!frm0!frm0Notes.Form!Note_ID

strNid =" Note_ID =" &安培; lngNid

Me.RecordSource =" qryNotesEntity"

设置rst = Me.RecordsetClone

rst.FindFirst strNid

Me.Bookmark = rst.Bookmark

Me.NavigationButtons = True

ElseIf Me.OpenArgs =" NewNote"然后

Me.NavigationButtons = False

结束如果

Me!txtNoteText.SetFocus

Exit_Here:

退出Sub

HandleErr:

Select Case Err.Number

Case Else

modHandler。 LogErr(frmNotesDetail),(Form_Open)

结束选择

简历Exit_Here

End Sub


尝试将表单的'Cycle属性设置为当前记录。


-

Allen Browne - Microsoft MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" deko" <无**** @ hotmail.com>在消息中写道

news:14 ******************* @ newssvr25.news.prodigy。 com ...

要查看当前活动的控件是什么,请尝试:
Screen.ActiveControl
谢谢 - 这似乎有效。但现在的问题是,在



当前记录滚动到字段的底部后,表单跳转到下一个
记录,这就是我的行为我试图避免。以下是代码:

Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
On Error GoTo HandleErr
Select Case KeyCode
案例33,34
如果Screen.ActiveControl<> Me.txtNoteText然后KeyCode = 0
结束选择
[代码省略]
End Sub

有没有办法阻止表单移动到下一条记录?

顺便说一下,这个表单的RecordSource是从克隆的
记录集构建的:
Private Sub Form_Open(取消为整数)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst as DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
如果Me.OpenArgs =OldNote然后
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid =" Note_ID =" &安培; lngNid
Me.RecordSource =" qryNotesEntity"
设置rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons =真的
ElseIf Me.OpenArgs =" NewNote"然后
Me.NavigationButtons = False
结束如果
我!txtNoteText.SetFocus
Exit_Here:
退出Sub
HandleErr:
Select Case Err .Number
Case Else
modHandler.LogErr(" frmNotesDetail"),(&#Form_Open")
结束选择
继续Exit_Here
End Sub



I have a form that I do *not* want the user to be able to use the
PageUp/PageDown keys *unless* the cursor is in a particular text box.

I''m using this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
KeyCode = 0
End Select
Exit Sub

But how do I allow use of the PageUp/PageDown keys within a particular text
box? The text box in question - txtNoteText - will contain a lot of text,
perhpas a few pages, that is populated from a memo field.

Thanks in advance.

I would also like to be able to use the mouse wheel to scroll in the text
box, but I am not sure if this is possible. I am using Stephen Lebans
MouseHook DLL, which turns off the mouse wheel in the form, but I cannot get
it to turn back on when the cursor is in the text box

I tried the below code, but it does not work. I would settle for use of the
PageUp / PageDown Key, however...

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

Private Sub txtNoteText_Exit(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub

解决方案

To see what the currently active control is, try:
Screen.ActiveControl

Be sure to use error handling. Lots can go wrong trying to read that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <no****@hotmail.com> wrote in message
news:Tv*******************@newssvr25.news.prodigy. com...

I have a form that I do *not* want the user to be able to use the
PageUp/PageDown keys *unless* the cursor is in a particular text box.

I''m using this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
KeyCode = 0
End Select
Exit Sub

But how do I allow use of the PageUp/PageDown keys within a particular text box? The text box in question - txtNoteText - will contain a lot of text,
perhpas a few pages, that is populated from a memo field.

Thanks in advance.

I would also like to be able to use the mouse wheel to scroll in the text
box, but I am not sure if this is possible. I am using Stephen Lebans
MouseHook DLL, which turns off the mouse wheel in the form, but I cannot get it to turn back on when the cursor is in the text box

I tried the below code, but it does not work. I would settle for use of the PageUp / PageDown Key, however...

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

Private Sub txtNoteText_Exit(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub



> To see what the currently active control is, try:

Screen.ActiveControl



Thanks - that seems to work. But the problem now is that after the current
record is scrolled to the bottom of the field, the form jumps to the next
record, which is the behavior I''m trying to avoid. Here is the code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo HandleErr
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
[code omitted]
End Sub

Is there a way to prevent the form from moving to the next record?

By the way, the RecordSource for this form is built form a cloned recordset:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub


Try setting the form''s Cycle property to Current Record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <no****@hotmail.com> wrote in message
news:14*******************@newssvr25.news.prodigy. com...

To see what the currently active control is, try:
Screen.ActiveControl
Thanks - that seems to work. But the problem now is that after the


current record is scrolled to the bottom of the field, the form jumps to the next
record, which is the behavior I''m trying to avoid. Here is the code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo HandleErr
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
[code omitted]
End Sub

Is there a way to prevent the form from moving to the next record?

By the way, the RecordSource for this form is built form a cloned recordset:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub



这篇关于如何测试光标是否在文本框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆