TPageControl gives away the focus to the first control of parent form
- Lazarus/FPC Version: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 x86_64-win64-win32/win64
- Operating System: Windows 10
- CPU / Bitness: 64 Bit
What happens
If you want to change page by clicking on tabs of PageControl, it's loosing focus, and external Control is focused instead.
What did you expect
Corresponding (i.e active) page of PageControl must receive focus when switching tabs.
Steps to reproduce
- Create new project.
- Place Edit1.
- Drop PageControl and create to pages in it.
- Place Edit2 to TabSheet1.
- Place Edit3 to TabSheet2.
- Compile and run app.
- You can see that Edit1 is focused.
- Click on Edit2 to set focus inside of TabSheet1.
- Click on TabSheet2 to switch to 2nd page.
You'll see, that PageControl1 looses focus at all and Edit1 is focused suddenly. But we expected that Edit3 on TabSheet2 will be focused instead.
Of course, we can mask this bug by calling SetFocus in PageContol1 handler like:
procedure TForm1.PageControl1Change(Sender: TObject);
begin
if PageControl1.ActivePage.CanSetFocus then
//mask LCL error
PageControl1.ActivePage.SetFocus;
end;
But Edit1 still will receive focus awhile and fires undesired OnEnter handler.
See attached example project:pagecontrolbug.zip