如何设置默认焦点自定义按钮控件? [英] How to set default focus on custom button control?

查看:63
本文介绍了如何设置默认焦点自定义按钮控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们在设置自定义按钮控件的默认焦点时遇到问题。我将尝试通过下面的一个简单示例来解释我们面临的问题。



我们创建了两个自定义按钮控件 - 表单上的确定和取消并设置了form的AcceptButton属性到OK按钮。理想情况下,这应该在表单加载时将默认焦点设置为确定按钮。但是当我们在运行时看到表单时,我们无法看到OK按钮的默认焦点。我们发现,只有当焦点转到另一个窗体时,默认焦点才会出现在第一个窗体的OK按钮上(默认焦点显示为按钮周围的粗线)。



您能帮助我们理解为什么默认焦点没有出现在表单加载的OK按钮上吗?我们是否还需要做一些额外的事情来解决这个问题?

Hi,

We are facing an issue with setting the default focus for a custom button control. I will try to explain the issue we are facing with a simple example below.

We had created two custom button controls - OK and Cancel on a form and had set the form's AcceptButton property to the OK button. Ideally this should set the default focus on the OK button on form load. But we are unable to see the default focus on OK button when we see the form in runtime. And we found that, only when the focus goes to another form, does the default focus appear on the OK button of the first form (default focus appears as a thick line around the button).

Could you kindly help us understand why the default focus does not appear on the OK button on form load? Do we have to do something additional to fix this?

推荐答案

在Windows中,焦点意味着用户可以通过键盘与此对象进行交互。因此,一个且仅一个对象可以一次具有焦点。如果FormB具有焦点,则FormA上的控件也不可能具有焦点。



因此,如果您需要在给定按钮周围保留边框,您需要创建一个自定义按钮,手动绘制按钮周围的边框。这有点超出了快速答案,但它相当简单,网上有很多例子。
In Windows, "focus" means "the user can interact with this object by way of the keyboard." As such, one and ONLY one object can have the focus at a time. If FormB has the focus, it is impossible for a control on FormA to also have the focus.

So, if you need to keep a border around a given button, you will need to create a custom button that manually draws a border around the button. That is a bit beyond a quick answer, but it is reasonably simple and there are many examples to be found on the web.


这篇关于如何设置默认焦点自定义按钮控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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