输入密钥模拟点击无效复选框 [英] Enter Key simulate click not working for checkboxes

查看:129
本文介绍了输入密钥模拟点击无效复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经复制并略微修改了位于这篇文章,以允许在我创建的工作表上的表单控件之间进行标签。以下是与KeyCode = vbKeyEnter相关的细分:

 选择案例KeyCode 
案例vbKeyTab
Dim Backward As Boolean
Backward =(Shift和fmShiftMask)

调用MoveFocus(Cntrl:= Cntrl,TabIndex:= TabIndex,Backward:= Backward)

案例vbKeyEnter
选择案例类型名称(Cntrl)
案例TxtBoxType
如果没有(Cntrl.EnterKeyBehavior和Cntrl.MultiLine)然后
调用MoveFocus(Cntrl:= Cntrl,TabIndex:= TabIndex)
结束如果
案例Else
关于错误简历Next
Application.Run Sheet1.CodeName& &安培; Cntrl.name& _Click
在错误GoTo 0
结束选择
结束选择

代码适用于在控件之间向前和向后标签。但是,使用确认键检查并取消选中复选框控件时遇到问题。它适用于选项按钮,但不起作用复选框。如果我在CheckBox1_Click事件中添加了 CheckBox1.Value = True ,它可以检查它是否正确,但是当然不会允许它取消选中。我尝试添加以下IF语句,将其设置为true或false,具体取决于当前值,但没有任何反应。

 如果CheckBox1.Value = True然后
CheckBox1.Value = False
Else
CheckBox1.Value = True
End If
解决方案


这可能是也可能不是编程问题的答案;我会让选民决定。输入密钥模拟点击不适用于复选框


你为什么要这样做?你花时间和精力有意地打破一个工作系统。 空格键长期以来一直是切换复选框的被接受的按键, Tab Shift + Tab 是用于在表单控件和之间导航输入 OK 的默认值。



通过工作系统我意味着整个Mac / Windows / Linux GUI系统和数百万受过长期定义的标准做法培训的人员。您可以将鼠标从任何合格的上班族中脱离出来,而且他们的生产力也不会受损。他们可以浏览系统和应用程序来完成工作,因为系统中的所有内容都从设置视频分辨率到将工作人员的时间卡数据输入到自定义表单中的工作方式与相同。



拿一个Windows用户,把它们放在他们的第一个Mac前面。他们可以使用程序并完成工作,因为绝大多数操作(特别是应用程序的基本操作)都是相同的。拿一个Mac用户,并将它们粘在Linux机器前面,您将获得相同的结果。机器及其程序的基本日常操作是一样的。



任何潜在申请人要求工作的意思是要填写简历如果您要创建一个拥有所有培训,实践和经验的专有系统并将其从窗口中扔出来的办公室经验?



使用 spacebar 可在Windows 3.0之前关闭和关闭复选框。建立更好的捕鼠器和重塑轮子之间有区别。






¹如果你不认为维护GUI标准是需要努力的,考虑Office 2007功能区创建的反弹。一个专门用于生产带来Office 2003功能的附加组件的整个子行业被推出。


I have copied and slightly modified the code found at the bottom of this post to allow tabbing between form controls on a worksheet form I have created. Here is the segment relating to the KeyCode = vbKeyEnter:

Select Case KeyCode
Case vbKeyTab
    Dim Backward As Boolean
    Backward = (Shift And fmShiftMask)

    Call MoveFocus(Cntrl:=Cntrl, TabIndex:=TabIndex, Backward:=Backward)

Case vbKeyEnter
    Select Case TypeName(Cntrl)
    Case TxtBoxType
        If Not (Cntrl.EnterKeyBehavior And Cntrl.MultiLine) Then
            Call MoveFocus(Cntrl:=Cntrl, TabIndex:=TabIndex)
        End If
    Case Else
        On Error Resume Next
        Application.Run Sheet1.CodeName & "." & Cntrl.name & "_Click"
        On Error GoTo 0
    End Select
End Select

The code works fine for tabbing forward and backward between controls. However, I'm having troubles using the enter key to check and uncheck check box controls. It works for option buttons, but does not work check boxes. If I add CheckBox1.Value = True to the CheckBox1_Click event it works to check it true, but naturally won't allow it to uncheck to false. I've tried adding the following IF statement to set it to true or false depending on current value, but then nothing happens.

If CheckBox1.Value = True Then
    CheckBox1.Value = False
Else
    CheckBox1.Value = True
End If

Another note: When I hit enter and nothing happens to the form control it moves the active cell down the active column. Any suggestions?

解决方案

This may or may not be an answer to the programming question; I will let the voters decide.
Q. Enter Key simulate click not working for checkboxes

Why would you do such a thing? You are spending time and effort to intentionally 'break' a working system. The spacebar has long been the accepted keystroke for toggling a checkbox on and off, Tab and Shift+Tab are used for navigating between form controls and Enter↵ is the default for OK.

By 'working system' I mean the whole Mac/Windows/Linux GUI system and the millions of people that have trained to work within long defined standard practises. You can take the mouse away from any competent office worker and their productivity will not suffer. They can navigate through the system and applications to perform their work because everything in the system from setting the video resolution to typing workers' timecard data into a custom form works the same way.

Take a Windows user and stick them in front of their first Mac. They can use the programs and get the job done because the vast majority of operations (and particularly the ones for basic operation of an application) are the same. Take a Mac user and stick them in front of a Linux machine and you will get the same results. The basic day-to-day operation of the machine and its programs are the same.

What is the point of any prospective applicant looking for employment to come with a CV filled with office experience if you are going to create a proprietary system that takes all of their training, practise and experience and throws it out the window?

The use of the spacebar to toggle a checkbox on and off predates Windows 3.0. There is a difference between building a better mousetrap and reinventing the wheel¹.


¹ If you don't think that maintaining GUI standards is something to strive for, consider the backlash that the Office 2007 ribbon created. An entire sub-industry dedicated to producing add-ons that brought back Office 2003 functionality was spawned.

这篇关于输入密钥模拟点击无效复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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