문제

D5pro.

I have a sub-form of the main app, Form1 with a Memo1 the the user can add text to.

I have a FormHelp that is only for viewing (contains MemoHelp.ReadOnly:=True).

In Form1 the FormHelp can be displayed by a button click on Form1, or automatically from a check box setting in the Setup.

Form1.OnShow...
if FormSetup.cbHelp.Checked then
  FormHelp.Show;

OR

Form1.BtnHelpClick(...
  FormHelp.Show;

I want to set the focus back to the Memo1 on Form1 after showing the Help window.

I have tried Memo1.SetFocus but that does not work.

I tried this Using WM_SETFOCUS and WM_KILLFOCUS and that did not work

I get an "Can't focus.." error with this How to force a focus on a component before the Form is shown

Can someone please show me how to put focus back to the Memo1

Thank you.

도움이 되었습니까?

해결책

You cannot call SetFocus on a control if its form does not have focus. And after the help form has shown, the memo's form no longer has focus. Instead, the help form has the focus.

So set the focus back to the form:

Form1.ActiveControl := Form1.Memo1;
Form1.SetFocus;

다른 팁

FormHelp gains the input focus when it is shown. Try calling BringToFront() on Form1 before then calling Memo1.SetFocus().

Just set the form's ActiveControl, either in the Object Inspector or in your code:

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