How do I set the first control in a tab order at startup? lazarus / 31-LCL ---------------------------------------------------------------------- AMJF · 2021-04-25 07:20 I have a form with many controls and I've arranged them so they focus in the order I tab them in, but I would like to know how to set one of the controls to be in focus at program startup? ---------------------------------------------------------------------- egsuh · 2021-04-25 07:35 You can force it focused setting control.focused := true, at OnShow or OnActivate event handler. ---------------------------------------------------------------------- AMJF · 2021-04-25 07:49 I notice that it's always the most recently added control that has the initial focus, isn't there a property that I can set the focus on rather than writing code to do so? ---------------------------------------------------------------------- egsuh · 2021-04-25 08:30 You will be able to do that by setting the taborder property of the control you want to be focused initially to 0. ---------------------------------------------------------------------- AMJF · 2021-04-25 08:37 I don't think so, not in my experience. I have the tab order set as I want it, but the control at 0 is NOT in focus at startup, but the control at 3 is. The control at 3 is the last one I added to the form, BTW. ---------------------------------------------------------------------- dseligo · 2021-04-25 08:46 You have ActiveControl property in Object Inspector where you can choose your active control without writing code. ---------------------------------------------------------------------- wp · 2021-04-25 09:08 I recently discovered that the "Tab Order" command in the context menu opens a dialog with a sort button and a checkbox "Recursively". When this checkbox is checked and the sort button is clicked the tab order of all controls is set in the order top/left to right/bottom, and the first control in the resulting list becomes the one which is automatically focused - without having to set the ActiveControl of the form. ---------------------------------------------------------------------- AMJF · 2021-04-25 09:43 I've solved the problem now, and have implemented ActiveControl anyway, just in case. Thanks! Background: I wrote a program in Lazarus last year that had no issues with the tab order and I didn't use or even know about ActiveControl then, but for this current case I think I know what went wrong: My program needs a configuration file to function, so I thought until it finds a valid one, I should disable the controls like buttons, list boxes and edit boxes. However, I chose not to do it in code at first, but to change them in the properties in Object Inspector instead, then enable it in code later. Afterwards, I added the control that was in focus at startup and forgot to disable it, so that's why it was in focus. I assume if a control is disabled, it will move to the first enabled one at startup? Anyway, I've fixed all the bugs and it's now working.