문제

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 ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top