How to force a focus on a component before the Form is shown

给你一囗甜甜゛ 提交于 2019-12-30 18:27:11

问题


I have to show (with showModal) a Form with many TEdit but I want to force the focus on a TEdit, but not always the same, depending on the context.

I can't use SetFocus before the ShowModal (because the Form is not activate) and use the Component Name or Tag is not convenient in my application. Do you have an idea ?


回答1:


The simplest way to achieve your goal, in my view, is to assign to the ActiveControl property for the form. You can do this before showing the form. When you form is later shown, the VCL framework will ensure that the ActiveControl is given input focus.

From the documentation:

If the form does not have focus, ActiveControl is the control on the form that will receive focus when the form receives focus.



来源:https://stackoverflow.com/questions/15428004/how-to-force-a-focus-on-a-component-before-the-form-is-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!