简体   繁体   English

按钮是自动选择的(如何关闭它?)

[英]Buttons Are Automatically Selected (how to turn this off?)

I have winform buttons that when you load the form, a certain button is selected.我有 winform 按钮,当您加载表单时,会选择某个按钮。 What I mean by selected, is that if "enter" is pressed, the button is pressed.我所说的选中的意思是,如果按下“输入”,则按下按钮。

How can I change my buttons so they don't do this anymore?我怎样才能改变我的按钮,让他们不再这样做?

Your tab order is set in the order in which you add controls on the form.您的 Tab 键顺序是按照您在表单上添加控件的顺序设置的。 If your first control which can be pressed/selected/edited is that button which is getting pressed, the focus will automatically be on it when form is loaded.如果您可以按下/选择/编辑的第一个控件是被按下的按钮,则在加载表单时焦点将自动位于该按钮上。

You can cheat by setting the focus to some other control (maybe which is not visible? !hint * hint!) to avoid the button to be selected at first.您可以通过将焦点设置到其他控件(也许哪个不可见?!提示 * 提示!)来作弊,以避免首先选择按钮。

But also make sure tht button is not the AcceptButton of the form.但也要确保按钮不是表单的 AcceptButton。

Two concepts have been touched on by Nayan and rerun: Nayan 触及了两个概念并重新运行:

1) AcceptButton 2) Tab order 1) 接受按钮 2) Tab 顺序

There is one more I would add and then try to explain how the three things relate:我还要添加一个,然后尝试解释这三件事之间的关系:

3) Focus 3) 专注

Focus means that a child control has the "keyboard focus".焦点意味着子控件具有“键盘焦点”。 When a control has focus, it receives keyboard input and can respond to it.当控件获得焦点时,它会接收键盘输入并对其做出响应。 Focus is changed either by clicking a control with the mouse, or by using the Tab key.通过使用鼠标单击控件或使用 Tab 键来更改焦点。

Tab order is the order in which controls receive focus when the Tab key is pressed. Tab 顺序是按下 Tab 键时控件接收焦点的顺序。 It also determains which control initially gets focus (the first one in tab order).它还确定哪个控件最初获得焦点(按 Tab 键顺序排列的第一个)。

The AcceptButton concept is a bit of a hybred. AcceptButton 概念有点混合。 If a form's AcceptButton property is set to a button control, that button is pressed when the user presses the Enter key while focus is on any control that does not process the enter key itself.如果窗体的 AcceptButton 属性设置为按钮控件,则当用户按下 Enter 键时,当焦点位于任何不处理 Enter 键本身的控件上时,就会按下该按钮。 Typically the 'Ok' button on a form is set as the AcceptButton so that the user can enter data and press Enter as a shortcut to pressing the Ok button.通常,表单上的“确定”按钮设置为“接受按钮”,以便用户可以输入数据并按 Enter 作为按下“确定”按钮的快捷方式。

您需要在表单上设置接受按钮

Element.Select() 对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM