Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Keeping the focus on the same form

I have two forms which are visible at all time. One has some buttons, the other one has a TEdit. I want the Tedit to have the focus at all time. When the user clicks on the button, of course the focus goes to that form. Is there a way to prevent a form to get the focus, even if a component on that form is clicked. Right now I just have a OnClick event for everything on the form with the button that sets the focus back to the form with the edit button. It works but I would prefer a cleaner solution, like a form property that prevents the form from getting the focus.
0
moonrise
Asked:
moonrise
1 Solution
 
jeurkCommented:
I don't think it's possible.
I would be interesed if it is.
0
 
viktornetCommented:
Are you trying to make a button to stay in the caption area of the first button?

Viktor Ivanov
0
 
viktornetCommented:
Are you trying to make a button to stay in the caption area of the first button?

Viktor Ivanov
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vladikaCommented:
Try make Form2(with Edit) modal.
After that you could not switch to Form1

0
 
JaccoCommented:
You can do one thing to do this.

first you install the following message handler on the form that you don't want to be activated:

procedure WMMouseActivate(var Message: TMessage); message WM_MOUSEACTIVATE;

implementation:

procedure TForm2.WMMouseActivate(var Message: TMessage);
begin
  Message.Result := MA_NOACTIVATE;
end;

Second you should you components on that form that cannot receive the focus:

in stead of TButton's use TSpeedButton's.

The only way your Form will get activated then is when the user starts to move your Form. If you want to disable that behaviour override the WM_NCHitTest message handler of the Form and return the value HTCLIENT.

procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;

procedure TForm2.WMNCHitTest(var Message: TWMNCHitTest);
begin
  Message.Result := HTCLIENT;
end;

Hope this helps you on the way!

Regards
Jacco
0
 
moonriseAuthor Commented:
Hi Jacco,

It works just as you said.  Thank you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now