Recent

Author Topic: [Solved] SynEdit setfocus?  (Read 3856 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
[Solved] SynEdit setfocus?
« on: June 30, 2015, 09:07:13 pm »
I'm trying to set focus to a synedit on my form on form creation, but when I try, I get: mainForm:TMainForm Can not focus
« Last Edit: July 01, 2015, 05:46:31 pm by Trenatos »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit setfocus?
« Reply #1 on: June 30, 2015, 10:19:44 pm »
Have you tried
Code: [Select]
  Form1.ActiveControl := SynEdit1;

Ensure the SynEdit (as any other control that is to receive focus) is visible and enabled, and all its parent controls are so too.

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: SynEdit setfocus?
« Reply #2 on: June 30, 2015, 10:24:31 pm »
I just tried putting SynEdit1.SetFocus; in the forms onPaint procedure, and that worked.

I'm guessing the SynEdit didn't exist at the point I was trying to set focus.

I was trying to set it in the formcreate procedure.

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: SynEdit setfocus?
« Reply #3 on: June 30, 2015, 10:26:35 pm »
And I now read that onPaint is a bad place for setting focus as it triggers often, so I moved it to onShow.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: SynEdit setfocus?
« Reply #4 on: June 30, 2015, 10:36:11 pm »
And I now read that onPaint is a bad place for setting focus as it triggers often, so I moved it to onShow.
NO. Just set the form's ActiveControl property to your synedit control on the constructor.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: SynEdit setfocus?
« Reply #5 on: June 30, 2015, 11:00:34 pm »
No idea what ActiveControl is

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: SynEdit setfocus?
« Reply #6 on: June 30, 2015, 11:25:59 pm »
No idea what ActiveControl is
already said so its a property you do something like Self.ActiveControl := Synedit1; and leave it alone when you form is shown synedit1 will be focused.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: SynEdit setfocus?
« Reply #7 on: July 01, 2015, 03:12:13 pm »
That works nicely, thanks taazz

 

TinyPortal © 2005-2018