焦点问题在表格加载 [英] Focus issue on Form Load

查看:137
本文介绍了焦点问题在表格加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActiveX控件(用VB 6.0或C ++编写),我们在C#WinForms程序中用作AxInterop。它非常像一个文本框,但有一些特殊的逻辑等...我们已经将其添加到工具栏。

当表单加载时,我希望键盘焦点在这个控制中,所以我用 .Focus .Select 方法,但仍然没有得到焦点。



当我从Visual Studio运行时,控件获得焦点。



在IDE中,控件没有得到重点。

这是为什么?



这里是一个截图它也是:




解决方案


$ b $是否确定组件是可见的? b

如果您尝试在 Form.Load 事件处理程序,请尝试将其移动到 Form.Shown 处理程序,或者 Control.Enter

行为上的差异可能归结为时间问题。
查看在MSDN上的事件顺序发生在一个开放的形式更多的想法。


I have an ActiveX control (written in VB 6.0 or C++ maybe) that we are using as an AxInterop in a C# WinForms program. It is very much like a text box but with some special logic etc... and we have added it to a toolbar.

When the form loads I want the keyboard focus to be inside this control, so I used .Focus and .Select methods on it but still it does NOT get the focus.

When I run from Visual Studio, the control gets the focus.

When I run outside of the IDE, the control does not get the focus.

Why is this?

Here is an screen shot of it too:

解决方案

Are you sure the component is visible when you try to give it focus?

If you are trying to do the focussing in a Form.Load event handler, try moving it to the Form.Shown handler instead, or perhaps Control.Enter.

The difference in behaviour could be down to a timing issue. Have a look on MSDN for the order in which events occur on an opening form for more ideas.

这篇关于焦点问题在表格加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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