How to force focus on a component before displaying a form

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

I cannot use SetFocus before ShowModal (because the form is not activated) and using the component name or tag in my application is not very convenient. Do you have an idea?

+8
delphi focus setfocus
source share
1 answer

The easiest way to achieve your goal, in my opinion, is to assign ActiveControl properties to the form. You can do this before showing the form. When you create one, it will be shown later that the VCL environment ensures that the ActiveControl set with input focus.

In the documentation:

If the form has no focus, ActiveControl is the control that will receive focus when the form receives focus.

+17
source share

All Articles