How to prevent form from being activated when the users clicks on it?

寵の児 提交于 2019-12-18 07:08:27

问题


I have a main form and non-modal autocomplete form. How can I prevent the autocomplete form from being activated by the user, when the user clicks on the list in the autocomplete form?

So, basically I want the autocomplete form the receive the mouse click message when the users clicks, but to never become active, because it causes problems with a third-party component in the main form over which I have no control.


回答1:


Override CreateParams method of your form and add WS_EX_NOACTIVATE style to the extended styles.

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;

  Params.WindowClass.ExStyle := Params.WindowClass.ExStyle or WS_EX_NOACTIVATE;
end;

(code written from memory, might contain typos)




回答2:


Use CreateParams (Alex T. answer) or you can try set YourForm.Enabled to False.



来源:https://stackoverflow.com/questions/2500678/how-to-prevent-form-from-being-activated-when-the-users-clicks-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!